فیلترهای مختلفی در افزونه رنک مث سئو گنجانده شده که توسعهدهندگان میتوانند از آنها برای تعامل با دادههای خروجی توسط رنک مث استفاده کنند. میتوانید…
آنچه در این مطلب خواهید خواند
فیلترهای مختلفی در افزونه رنک مث سئو گنجانده شده که توسعهدهندگان میتوانند از آنها برای تعامل با دادههای خروجی توسط رنک مث استفاده کنند. میتوانید دادههای رنک مث را از درون تم/افزونههای خود کنترل کنید. قبل از بررسی فیلترها و قلابهای مختلفی که رنک مث ارائه میدهد، در مورد نحوه افزودن آنها به وبسایت خود صحبت میکنیم.
افزودن فیلترها و قالب ها به functions.php تم شما در عمل یک روش رایج است و وقتی اضافه شود، در اکثر موارد به خوبی کار می کنند. اما، ما شما را تشویق می کنیم که این فیلترها را wp-content/themes/theme-name/rank-math.php به آن اضافه کنید، زیرا مزایایی مانند موارد زیر را شامل می شود:
هنگامی که قطعه کد را به functions.php طرح زمینه خود اضافه می کنید، در معرض خطر از دست دادن تمام سفارشی سازی های اضافه شده در هنگام تغییر تم قرار می گیرید، و شناسایی تمام کدهای رنک مث استفاده شده و افزودن آن به تم جدیدتان واقعا خسته کننده خواهد بود.
با افزودن تمام کدهای رنک مث در یک فایل جداگانه، انعطاف پذیری لازم برای تغییر تم ها را خواهید داشت. تنها کاری که باید انجام دهید این است که یک کپی از فایل rank-math.php خود را از قالب قدیمی خود دانلود کرده و آن را در پوشه تم جدید خود آپلود کنید. سپس، همه سفارشیسازیهای رنک مث شما به همان روش قبلی کار خواهند کرد.
هنگامی که فیلتری را به functions.php قالب خود اضافه می کنید، حتی زمانی که پلاگین رنک مث فعال نباشد، کد روی وب سایت شما اجرا می شود. اما وقتی به فایل .php رنک مث اضافه می شود، کد فقط زمانی اجرا می شود که پلاگین رنک مث فعال باشد، زیرا افزونه شامل فایل است. این تمرین به شما کمک می کند تا مطمئن شوید که سایت شما با بیشترین سرعت ممکن اجرا می شود.
برخی از فیلترها مانند فیلترهای شخصی سازی OpenGraph باید در wp_head نوشته شوند. دلایل زیادی وجود دارد که چرا آنها ممکن است هنگام اضافه شدن به functions.php آنطور که در نظر گرفته شده است عمل نکنند، و برای اینکه مطابق انتظار کار کنند، باید به rank-math.php اضافه شوند.
برای اینکه کارها پیچیده نشود، توصیه می کنیم به جای اضافه کردن آنها به functions.php، همه توابع رنک مث را به rank-math.php اضافه کنید.
برای شروع اضافه کردن کد به rank-math.php، ابتدا باید فایل را ایجاد کنید. شما به راحتی می توانید این کار را با یک FTP یا cPanel File Manager انجام دهید.
اگر از FTP استفاده می کنید، به پوشه تم خود بروید (/wp-content/themes/theme-name/) و سپس یک فایل جدید با نام rank-math.php مانند شکل زیر ایجاد کنید:
اگر از cPanel استفاده میکنید، میتوانید از File Manager آنها برای ایجاد فایل جدید خود با نام rank-math.php در پوشه تم (/wp-content/themes/theme-name/) مانند شکل زیر استفاده کنید.
هنگامی که فایل رنک مث را در پوشه تم خود ایجاد کردید، می توانید فایل را با رفتن به Appearance > Theme File Editor (برای تم کلاسیک) یا Tools > Theme File Editor (برای Block Theme) در قسمت مدیریت وردپرس خود ویرایش کنید.
سمت راست صفحه شما همه فایلهای تم و قالبها را فهرست میکند. فایل هایی که در اینجا نشان داده می شوند بسته به موضوعی که در وب سایت خود استفاده می کنید متفاوت است. می توانید از لیست فایل ها به فایل rank-math.php که در مرحله قبل ایجاد کرده بودید دسترسی داشته باشید.
شما میتوانید ویرایشگر کد موجود در وسط صفحه خود را ببینید، و میتوانید تکههای کد را اضافه کنید (که به زودی در این مقاله به آن خواهیم پرداخت).
هنگامی که قطعه کد را اضافه کردید، روی دکمه Update File در پایین صفحه کلیک کنید تا تغییرات شما ذخیره شود.
در حین افزودن قطعه کد، اگر به طور تصادفی اشتباهی مرتکب شده باشید که باعث از کار افتادن سایت شما شود، ویرایشگر فایل تم بدون ذخیره کردن فایل با خطا مواجه می شود تا بتوانید فوراً آنها را برطرف کنید. هنگامی که فایل را با موفقیت به روز کردید، می توانید سایت خود را برای تغییرات آماده کنید.
اکنون که نحوه استفاده از فایل rank-math.php را فهمیدیم، به فیلترها و قلاب های مختلفی که برای استفاده شما در دسترس است نگاه می کنیم.
از این فیلتر برای تغییر اولویت متاباکس رنک مث به low استفاده کنید، بنابراین بعد از سایر متاباکسها مانند فیلدهای ACF ظاهر میشود.
[php]
/**
* Change the Rank Math Metabox Priority
*
* @param array $priority Metabox Priority.
*/
add_filter( 'rank_math/metabox/priority', function( $priority ) {
return 'low';
});
[/php]
از این فیلتر برای افزایش یا کاهش تعداد کلمات کلیدی اصلی که می توانند در ویرایشگر پست یا صفحه اضافه شوند، استفاده کنید. کاربران رنک مث PRO در حال حاضر توانایی اضافه کردن نامحدود کلمات کلیدی را دارند و این فیلتر تعداد کلمات کلیدی را برای کاربران PRO محدود نخواهد کرد.
/**
* Change the Focus Keyword Limit
*/
add_filter( 'rank_math/focus_keyword/maxtags', function() {
return 10; // Number of Focus Keywords.
});
این فیلتر به شما امکان می دهد بخشی را از پنل تنظیمات عمومی افزونه رنک مث اضافه یا حذف کنید.
/**
* Allow developers to add new section into general setting option panel.
*
* @param array $tabs
*/
add_filter( 'rank_math/settings/general', function( $tabs) {
unset( $tabs['htaccess'] ); // Unsets Edit .htaccess tab.
return $tabs;
});
با این تنظیم می توانید یک بخش سفارشی را به گزینه تنظیمات عنوان اضافه یا حذف کنید.
/**
* Allow developers to add new section into general setting option panel.
*
* @param array $tabs
*/
add_filter( 'rank_math/settings/title', function( $tabs) {
return $tabs;
});
/**
* Allow developers to add option fields to check against updatation.
* And if updated flush the rewrite rules.
*
* @param array $flush_fields Array of fields id for which we need to flush.
*/
add_filter( 'rank_math/flush_fields', function( $fields) {
return $fields;
});
/**
* Allow developers to add new tabs into option panel.
*
* The dynamic part of hook is, page name without 'rank-math-' prefix.
*
* @param array $tabs
*/
add_filter( "rank_math/admin/options/{$filter}_tabs", function( $tabs ) {
return $tabs;
});
این فیلتر به شما امکان می دهد تست های تحلیل محتوا را اضافه/به روز کنید/حذف کنید. برای حذف هر آزمونی، میتوانید به سادگی تست را همانطور که در این آموزش نشان داده شده است ، از حالت تنظیم خارج کنید .
/**
* Allow developers to modify the test or score.
*
* @param array $tests Array of tests with score
* @param string $type Object type. Can be post, user or term.
*/
add_filter( 'rank_math/researches/tests', function( $tests, $type ) {
return $tests;
}, ۱۰, ۲ );
/**
* Number of items to import per run.
*
* @param int $items_per_page Default 100.
*/
add_filter( 'rank_math/importers/items_per_page', function( $items_per_page ) {
return $items_per_page;
});
آیتمی را از منوی نوار مدیریت وردپرس اضافه یا حذف کنید که رنک مث به قسمت جلویی وب سایت وردپرس شما اضافه می کند.
/**
* Add item to Rank Math admin bar node.
*
* @param array $items Array of nodes for Rank Math menu.
*/
add_filter( 'rank_math/admin_bar/items', function( $items ) {
return $items;
});
هنگامی که رنک مث در وب سایت WP نصب می شود، یک مقدار پیش فرض را برای تنظیمات عمومی تنظیم کنید. به گزینه ها و مقادیر پیش فرض در اینجا مراجعه کنید .
/**
* Add defaults for general options.
*
* @param array $settings Array of settings and its values.
*/
add_filter( 'rank_math/settings/defaults/general', function( $settings ) {
return $settings;
});
هنگامی که رنک مث در یک وب سایت نصب می شود، از این فیلتر برای تنظیم مقادیر پیش فرض برای تنظیمات SEO عنوتو متا استفاده کنید. به گزینه ها و مقادیر پیش فرض در اینجا مراجعه کنید .
/**
* Add defaults for title options.
*
* @param array $settings Array of settings and its values.
*/
add_filter( 'rank_math/settings/defaults/titles', function( $settings ) {
return $settings;
});
از فیلتر برای تنظیم مقادیر پیش فرض برای تنظیمات نقشه سایت استفاده کنید. به گزینه ها و مقادیر پیش فرض در اینجا مراجعه کنید .
/**
* Add defaults for Sitemap options.
*
* @param array $settings Array of settings and its values.
*/
add_filter( 'rank_math/settings/defaults/sitemap', function( $settings ) {
return $settings;
});
/**
* Filters the array of modules available to be activated.
*
* @param array $modules Array of available modules.
*/
add_filter( 'rank_math/modules', function( $modules ) {
return $modules;
});
این فیلتر به شما امکان می دهد قالب قسمت آدرس را برای کد کوتاه تماس سئو محلی رنک مث تغییر دهید .
/**
* Allow developer to change the address part format.
*
* @param string $parts_format String format how to output address part.
*/
add_filter( 'rank_math/shortcode/contact/address_parts_format', function( $format ) {
return $format;
});
/**
* Allow developer to change post types icons.
*
* @param array $icons Array of available icons.
*/
add_filter( 'rank_math/post_type_icons', function( $icons ) {
return $icons;
});
/**
* Allow developer to change taxonomies icons.
*
* @param array $icons Array of available icons.
*/
add_filter( 'rank_math/taxonomy_icons', function( $icons ) {
return $icons;
});
/**
* Allow developer to enable/disable overlay icon option in Post Settings.
*
* @param string $value Default is set to off.
* @param string $service Can be faceboo or twitter.
*
*/
add_filter( 'rank_math/metabox/social/overlay_icon', function( $value, $service ) {
return $value;
}, ۱۰, ۲ );
/**
* Allow developer to enable/disable Link Suggestion Metabox for specific post type.
*
* @param string $default Default is set to on.
* @param string $post_type Post type name.
*
*/
add_filter( 'rank_math/settings/titles/link_suggestions', function( $default, $post_type ) {
return $default;
}, ۱۰, ۲ );
از این فیلتر برای تنظیم یک نوع طرحواره پیش فرض برای هر نوع پست در رنک مث > تنظیمات عناون و متا استفاده کنید.
/**
* Allow developer to default Snippet type by post type.
*
* @param string $type Snippet Type.
* @param string $post_type Post type name.
*
*/
add_filter( 'rank_math/settings/snippet/type', function( $type, $post_type ) {
return $default;
}, ۱۰, ۲ );
/**
* Allow developer to default Snippet Article type by post type.
*
* @param string $type Article Type.
* @param string $post_type Post type name.
*
*/
add_filter( 'rank_math/settings/snippet/article_type', function( $type, $post_type ) {
return $default;
}, ۱۰, ۲ );
از این فیلتر برای تغییر name, descriptionو متغیرهای رنک مث موجود استفاده کنید variable . example
/**
* Filter to add custom variables
*/
add_filter( 'rank_math/vars/replacements', function( $vars ) {
return $vars;
});
این فیلتر به شما امکان می دهد متغیرهای دیگری را اضافه کنید که در منوی کشویی عنوان و متا رنک مث و همچنین در Meta Box Snippet Editor ظاهر می شوند.
/**
* Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
*/add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'custom_variable_slug',
[
'name' => esc_html__( 'Custom variable name.', 'rank-math' ),
'description' => esc_html__( 'Custom variable description.', 'rank-math' ),
'variable' => 'custom_variable_slug',
'example' => 'custom_variable_callback()',
],
'custom_variable_callback()'
);
});
/**
* Filter to show/hide SEO Metabox.
*/
add_filter( 'rank_math/metabox/add_seo_metabox', function( $default ) {
return $default;
});
این فیلتر به شما امکان می دهد جداکننده پیش فرضی را تنظیم کنید که در تگ های عنوان استفاده می شود. اگر نویسه جداکننده با استفاده از این فیلتر تنظیم شود، نویسه جداکننده که توسط کاربران در زیر رتبه ریاضی > عنوان و متا > متای جهانی تنظیم شده است، لغو می شود .
/**
* Filter to change Separator %sep%.
*/
add_filter( 'rank_math/settings/title_separator', function( $sep ) {
return $sep;
});
/**
* Filter to turn off auto-update notification emails.
*/
add_filter( 'rank_math/auto_update_send_email', '__return_false' );
/**
* Filter to edit the auto-update notification emails.
*/
add_filter( 'rank_math/auto_update_email', function( $email, $version, $plugin_upgrader_obj ) {
$email['to_address'] = 'email@example.com';
$email['body'] = "Rank Math has been updated to version {$version}.";
return $email;
});
/**
* Filter to hide the Email Reporting Options
*/
add_filter( 'rank_math/analytics/hide_email_report_options', '__return_true' );
add_filter( 'rank_math/analytics/email_report_parameters', function( $data ) {
$data['to'] = get_option( 'admin_email' );
return $data;
} );
add_filter( 'rank_math/analytics/email_report_variables', function( $vars ) {
$vars['report_url'] = "https:://newlogin-url.com";
return $vars;
} );
/**
* Filter to change the Post Meta Table Limit
*/
add_filter('rank_math/seo_analysis/postmeta_table_limit', function ( $limit ) {
return 500000;
}
);
این فیلتر بررسی هرگونه عدم تطابق در آدرس سایت و URL وردپرس را در تنظیمات که میتواند باعث بروز مشکلاتی در فعالسازی در برخی تنظیمات شود، دور میزند.
/**
* Filter whether we need to check for URL mismatch or not.
*/
add_filter( 'rank_math/registration/do_url_check', '__return_false' );
/**
* Filter to disable sensitive data encryption
*/
add_filter( 'rank_math/admin/sensitive_data_encryption', '__return_false' );
/**
* Filter to Disable Keyword Suggestions from Google
*/
add_filter( 'rank_math/metabox/values', function( $args = [] ) {
$args['autoSuggestKeywords'] = false;
return $args;
} );
/**
* Filter to modify the redirection data before updating a redirection.
* Pass a false value to skip the update and create a new redirection instead.
*
* @param array|false $data Redirection data.
*/
add_filter('rank_math/admin/csv_import_redirection_update', function ($exist, $data) {
return $data;
}, ۱۰, ۲);
/**
* Filter to change the Sitemap URL Base
*
* @param string $base New URL Base
*/
add_filter( 'rank_math/sitemap/base_url', function( $base ){
return '/search-sitemaps/';
}, ۱۰, ۱ );
/**
* Filter XML sitemap cache directory.
*
* @param string $unsigned Default cache directory
*/
add_filter( 'rank_math/sitemap/cache_directory', function( $directory) {
return $directory;
});
/**
* Filter if XML sitemap transient cache is enabled.
*
* @param boolean $unsigned Enable cache or not, defaults to true
*/
add_filter( 'rank_math/sitemap/enable_caching', '__return_true');
/**
* Filter to change sitemap caching mode
*
* @param string $mode Cache mode "file" or "db".
*/
add_filter( 'rank_math/sitemap/cache_mode', function( $mode ) {
return $mode;
} );
این فیلتر گزینه Include in Sitemap موجود در رنک مث < تنظیمات نقشه سایت < نوع پست را لغو می کند .
/**
* Filter decision if post type is excluded from the XML sitemap.
*
* @param bool $exclude Default false.
* @param string $type Post type name.
*/
add_filter( 'rank_math/sitemap/exclude_post_type', function( $exclude, $type ){
return $exclude;
}, ۱۰, ۲ );
/**
* Filter the URL Rank Math SEO uses in the XML sitemap for this post type archive.
*
* @param string $archive_url The URL of this archive
* @param string $post_type The post type this archive is for.
*/
add_filter( 'rank_math/sitemap/post_type_archive_link', function( $archive_url, $post_type ){
return $archive_url;
}, ۱۰, ۲ );
/**
* Filter the URL Rank Math SEO uses in the XML sitemap.
*
* Note that only absolute local URLs are allowed as the check after this removes external URLs.
*
* @param string $url URL to use in the XML sitemap
* @param object $post Post object for the URL.
*/
add_filter( 'rank_math/sitemap/xml_post_url', function( $url, $post){
return $url;
}, ۱۰, ۲ );
این فیلتر گزینه Include in Sitemap موجود در Rank Math > Sitemap Settings > Taxonomies را لغو می کند.
/**
* Filter decision if taxonomy is excluded from the XML sitemap.
*
* @param bool $exclude Default false.
* @param string $type Taxonomy name.
*/
add_filter( 'rank_math/sitemap/exclude_taxonomy', function( $exclude, $type ){
return $exclude;
}, ۱۰, ۲ );
/**
* Filter the setting of excluding empty terms from the XML sitemap.
*
* @param boolean $exclude Defaults to true.
* @param array $taxonomy_names Array of names for the taxonomies being processed.
*/
add_filter( 'rank_math/sitemap/exclude_empty_terms', function( $exclude , $taxonomy_names ){
return $exclude;
}, ۱۰, ۲ );
/**
* Filter images to be included for the post in XML sitemap.
*
* @param array $images Array of image items.
* @param int $post_id ID of the post.
*/
add_filter( 'rank_math/sitemap/urlimages', function( $images, $post_id ){
return $images;
}, ۱۰, ۲);
/**
* Filter to remove sitemap credit.
*
* @param boolean Defaults to false.
*/
add_filter( 'rank_math/sitemap/remove_credit', '__return_true');
/**
Filter to add extra URLs to the XML sitemap by type.
*
Only runs for the first page, not on all.
*
@param string $content String content to add, defaults to empty.
*/
add_action( 'rank_math/sitemap/{$type}_content', function() {
return '<url>
<loc>https://rankmath.com/some-custom-url/</loc>
<lastmod>2020-06-10T20:20:20+00:00</lastmod>
</url>';
});
{$type}به ترتیب با یک postیا pageبسته به اینکه می خواهید URL در نقشه سایت پست یا صفحه قرار گیرد جایگزین کنید .
/**
* Filter to add Locations KML file in the sitemap
*/
add_filter( 'rank_math/sitemap/locations', '__return_true' );
/**
* Filter to Add CDN Image URLs in the Sitemap
*
* @param string $src Image URL.
* @param object $post Post object.
*/
add_filter( 'rank_math/sitemap/xml_img_src', function( $src, $post ){
$src = str_replace( 'http://domain.com', 'https://cdn.domain.com', $src );
return $src;
}, ۱۰, ۲);
/**
* Filter to detect Sitemap URL in the Search Console if you are using different plugin for sitemap.
*/
add_filter( 'rank_math/sitemap/sitemap_index_uri', function() { return 'sitemap.xml'; } );
/**
* Filter to change user query arguments for the sitemap listing
*/
add_filter( 'rank_math/sitemap/author/query', function( $args ) {
$args['role__not_in'] = 'subscriber'; return $args;
} );
/**
* Filter to add `noindex` URLs in the Sitemap
*
* @param bool $value Whether to include noindex terms in Sitemap.
* @param string $type Object Type.
*
* @return boolean
*/
add_filter( 'rank_math/sitemap/include_noindex', function( $value, $type ) {
return true;
}, ۱۰, ۲ );
add_filter( 'rank_math/sitemap/index', function( $xml ) {
$xml .= '
<sitemap>
<loc>http://example.com/new-sitemap.xml</loc>
<lastmod>2020-09-14T20:34:15+00:00</lastmod>
</sitemap>';
return $xml;
}, ۱۱ );
/**
* Filter to add links in the new Sitemap.
*/
add_filter( 'rank_math/sitemap/{$type}/content', function() {
return '
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://example.com/new-sitemap-post/</loc>
<lastmod>2020-09-14T20:34:15+00:00</lastmod>
</url>
</urlset>';
} );
/**
* Filter the sitemap HTTP headers.
*
* @param array $headers HTTP headers.
* @param bool $is_xsl Whether these headers are for XSL.
*/
add_filter( 'rank_math/sitemap/http_headers', function( $headers ) {
if ( '/locations.kml' !== $_SERVER['REQUEST_URI'] ) {
return $headers;
}
unset( $headers['X-Robots-Tag'] );
return $headers;
} );
/**
* Filter: 'rank_math/sitemap/content_before_parse_html_images' - Filters the post content
* before it is parsed for images.
*
* @param string $content The raw/unprocessed post content.
* @param int $post_id The current Post ID.
*/
add_filter( 'rank_math/sitemap/content_before_parse_html_images', function( $content, $post_id ) {
// Process content..
return $content;
}, ۱۰, ۲ );
/**
* Filter: 'rank_math/sitemap/html_sitemap/sort_items' - Allow changing the sort order of the HTML sitemap.
*
* @var array $sort {
* @type string $field The field to sort by.
* @type string $order The sort order.
* }
* @var string $type The item type.
* @var string $name The post type/taxonomy name.
*/
add_filter('rank_math/sitemap/html_sitemap/sort_items', function ($sort, $type, $name) {
return $sort;
}, ۱۰, ۳);
/**
* Filter: 'rank_math/sitemap/html_sitemap_post_statuses' - Allow changing the post statuses that should be included in the HTML sitemap.
*
* @var array $statuses Post statuses.
* @var string $post_type Post type name.
*/
add_filter('rank_math/sitemap/html_sitemap_post_statuses', function ($statuses, $post_type) {
return $statuses;
}, ۱۰, ۲);
/**
* Filter: 'rank_math/sitemap/html_sitemap_post_types' - Allow changing the post types to be included in the HTML sitemap.
*
* @var array $post_types The post types to be included in the HTML sitemap.
*/
add_filter('rank_math/sitemap/html_sitemap_post_types', function ($post_types) {
return $post_types;
}, ۱۰, ۱);
/**
* Filter: 'rank_math/sitemap/html_sitemap_taxonomies' - Allow changing the taxonomies to be included in the HTML sitemap.
*
* @var array $taxonomies The taxonomies to be included in the HTML sitemap.
*/
add_filter('rank_math/sitemap/html_sitemap_taxonomies', function ($taxonomies) {
return $taxonomies;
}, ۱۰, ۱);
/**
* Filter to remove HTML sitemap tab from the Sitemap settings.
*
* @param array $tabs
*/
add_filter( 'rank_math/settings/sitemap', function( $tabs) {
if ( isset( $tabs['html_sitemap'] ) ) {
unset( $tabs['html_sitemap'] );
}
return $tabs;
});
در فیلتر زیر، برای تغییر مکان تصویر کوچک و برای تغییر مکان محتوا ، آن را جایگزین {$prop}کنیدthumbnail_loccontent_loc
/**
* Filter the video content and thumbnail location:
* - rank_math/sitemap/video/thumbnail_loc
* - rank_math/sitemap/video/content_loc
*/
add_filter("rank_math/sitemap/video/{$prop}", function ($loc) {
return $loc;
});
/**
* Filter to prevent adding podcast data in the WP feeds.
*/
add_filter( 'rank_math/podcast/enhance_all_feeds', '__return_false' );
/**
* Filter to remove the Podcast feed namespace.
*/
add_filter( 'rank_math/rss/add_podcasts_namespace', '__return_false' );
/**
* Filter to modify the hub URLs.
*
* @param array $urls The HUB URLs.
*/
add_filter( 'rank_mathpodcast/hub_urls', function( $urls ) {
return $urls
} );
/**
* Filter to prevent Rank Math from automatically publishing feed to Pubhubsubbub.
*
* @param array $urls The HUB URLs.
*/
add_filter( 'rank_math/podcast/hub_urls', '__return_false' );
/**
* Filter to change the User-agent used to publish the feed to Pubhubsubbub.
*
* @param string $user_agent The user agent.
*/
add_filter( 'rank_math/podcast/useragent', function( $user_agent ) {
return $user_agent;
} );
/**
* Filter: 'rank_math/schema/podcast_episode_title' - Allow changing the title of the podcast episode. Pass false to disable.
*
* @var string $episode_title The title of the podcast episode.
*
* @param WP_Post $post The post object.
* @param array $schema The schema array.
*/
add_filter('rank_math/schema/podcast_episode_title', function( $episode_title, $post, $schema ) {
return $episode_title;
}, ۱۰, ۳);
فیلتر گزینههای خرده نان انتخاب شده توسط کاربر را در Rank Math > General Settings > Breadcrumbs لغو میکند
/**
* Filter to change breadcrumb settings.
*
* @param array $settings Breadcrumb Settings.
* @return array $setting.
*/
add_filter( 'rank_math/frontend/breadcrumb/settings', function( $settings ) {
$settings = array(
'home' => true,
'separator' => '',
'remove_title' => '',
'hide_tax_name' => '',
'show_ancestors' => '',
);
return $settings;
});
فیلتر رشتههای خردههای نان را که توسط کاربر در زیر رتبه ریاضی > تنظیمات عمومی > خردههای نان انتخاب شده است، لغو میکند .
/**
* Filter to change breadcrumb strings.
*
* @param array $settings Breadcrumb Strings.
* @return array $strings.
*/
add_filter( 'rank_math/frontend/breadcrumb/strings', function( $strings ) {
$strings = array(
'prefix' => '',
'home' => '',
'error404' => '',
'archive_format' => '',
'search_format' => '',
);
return $strings;
});
این فیلتر به شما امکان می دهد آرگومان های breadcrumb و ظاهر خرده نان را در قسمت جلویی نیز تغییر دهید.
/**
* Filter to change breadcrumb args.
*
* @param array $args Breadcrumb args.
* @return array $args.
*/
add_filter( 'rank_math/frontend/breadcrumb/args', function( $args ) {
$args = array(
'delimiter' => ' / ',
'wrap_before' => '<nav class="rank-math-breadcrumb"><p>',
'wrap_after' => '</p></nav>',
'before' => '',
'after' => '',
);
return $args;
});
این فیلتر به شما امکان می دهد هر گونه تغییری را در Breadcrumb HTML در قسمت جلویی ایجاد کنید.
/**
* Filter to change breadcrumb html.
*
* @param html $html Breadcrumb html.
* @param array $crumbs Breadcrumb items
* @param class $class Breadcrumb class
* @return html $html.
*/
add_filter( 'rank_math/frontend/breadcrumb/html', function( $html, $crumbs, $class ) {
// theme_breadcrumb_function();
return $html;
}, ۱۰, ۳);
می توانید از این فیلتر برای تغییر کلاس breadcrumbs در قسمت جلویی استفاده کنید.
/**
* Filter to change the primary term output of the breadcrumbs class.
*
* @param WP_Term $term Primary term.
* @param array $terms Terms attached to the current post.
*/
add_filter( 'rank_math/frontend/breadcrumb/main_term', function( $current_term, $terms ) {
return $current_term;
}, ۱۰, ۲ );
این فیلتر به توسعه دهندگان این امکان را می دهد که هر گونه تغییری ایجاد کنند یا هر آیتم breadcrumbs را به صورت پویا در قسمت جلویی حذف کنند. وقتی آیتم پودر سوخاری را با این فیلتر تغییر میدهید/حذف میکنید، تغییرات در طرحواره Breadcrumb نیز منعکس میشوند.
/**
* Allow changing or removing the Breadcrumb items
*
* @param array $crumbs The crumbs array.
* @param Breadcrumbs $this Current breadcrumb object.
*/
add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
return $crumbs;
}, ۱۰, ۲);
تغییرات ایجاد شده با استفاده از این فیلتر فقط بر روی Breadcrumb Schema تأثیر می گذارد.
/**
* Allow changing Breadcrumb elements in BreadcrumbList snippet
*
* @param array $entity Breadcrumb entity
*/
add_filter( 'rank_math/snippet/breadcrumb', function( $entity ) {
return $entity;
});
/**
* Filter to change the page title.
*
* @param string $title
*/
add_filter( 'rank_math/frontend/title', function( $title ) {
return $title;
});
/**
* Code to move title inside the Rank Math's meta
*
* @param string $title
*/
add_action( 'init', function() {
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
add_action( 'rank_math/head', '_wp_render_title_tag', 1 );
});
/**
* Allow changing the meta description sentence from within the theme.
*
* @param string $description The description sentence.
*/
add_filter( 'rank_math/frontend/description', function( $description ) {
return $description;
});
/**
* Use the Description from Global Setting, if the description is missing in the Post metabox
*/
add_action( 'rank_math/frontend/description', function( $description ) {
global $post;
$desc = RankMath\Post::get_meta( 'description', $post->ID );
if ( ! $desc ) {
$desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
if ( $desc ) {
return RankMath\Helper::replace_vars( $desc, $post );
}
}
return $description;
});
از این فیلتر برای تغییر متای روباتهای اضافه شده توسط رنک مث به صورت پویا در قسمت جلویی استفاده کنید.
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
return $robots;
});
/**
* Allow changing of the canonical URL.
*
* @param string $canonical The canonical URL.
*/
add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
return $canonical;
});
/**
* Filter to remove the plugin credit notice added to the source.
*
*/
add_filter( 'rank_math/frontend/remove_credit_notice', '__return_true' );
/**
* Allows developers to handle rel="next" / rel="prev" by themselves.
*
* @param bool $links_generated Whether or not to handle rel="next" / rel="prev" links.
*/
add_filter( 'rank_math/frontend/disable_adjacent_rel_links', '__return_true' );
/**
* Allow the changing of link rel output by Rank Math.
*
* @param string $link The full `<link` element.
* $rel can be next or prev
*/
add_filter( "rank_math/frontend/{$rel}_rel_link", function( $link ) {
return $link;
});
/**
* Add <meta name="keywords" content="focus keywords">.
*/
add_filter( 'rank_math/frontend/show_keywords', '__return_true');
/**
* Allow changing the meta keywords from the default Focus Keywords.
*
* @param string $keywords Keywords.
*/
add_filter( 'rank_math/frontend/keywords', function( $keywords ) {
return $keywords;
});
/**
* Allow shortcodes in the Meta Data.
*/
add_filter( 'rank_math/paper/auto_generated_description/apply_shortcode', '__return_true' );
/**
* Filter to allow shortcodes in the Product schema description.
*/
add_filter( 'rank_math/product_description/apply_shortcode', '__return_true' );
از این فیلتر برای تغییر نوع OpenGraph برای صفحه خاص در قسمت جلویی استفاده کنید.
/**
* Allows theme developers to change the OpenGraph type of the page.
*
* @param string $type The OpenGraph type string.
*/
add_filter( 'rank_math/opengraph/type', function( $type ) {
return $type;
});
/**
* Allows the output of the canonical URL as OpenGraph URL, consolidating likes and shares.
*
* @link https://developers.facebook.com/docs/reference/opengraph/object-type/article/
* @param $url Canonical URL
*/
add_filter( 'rank_math/opengraph/url', function( $url ) {
return $url;
});
/**
* Allows changing the Twitter Card type as output in the Twitter card.
*
* @param string $type
*/
add_filter( 'rank_math/opengraph/twitter_card', '__return_false' );
/**
* Allows developers to change the OpenGraph image within theme.
*
* The dynamic part of the hook name. $network, is the network slug. Can be facebook or twitter.
*
* @param string $attachment_url The image we are about to add.
*/
add_filter( "rank_math/opengraph/{$network}/image", function( $attachment_url ) {
return $attachment_url;
});
/**
* Allows developers to add images to the OpenGraph tags within the theme.
*
* The dynamic part of the hook name. $network, is the network slug. Can be facebook or twitter.
*
* @param Image The current object.
*/
add_filter( 'rank_math/opengraph/{$network}/add_additional_images', function( $image ) {
return $image;
});
/**
* Passing a truthy value to the filter will effectively short-circuit the
* set default image process.
*
* @param bool $return Short-circuit return value. Either false or true.
*/
add_filter( 'rank_math/opengraph/pre_set_default_image', '__return_true' );
/**
* Passing a truthy value to the filter will effectively short-circuit the
* set content image process.
*
* @param bool $return Short-circuit return value. Either false or true.
* @param int $post_id Post ID for the current post.
*/
add_filter( 'rank_math/opengraph/pre_set_content_image', function( $return, $post_id ) {
return $return; // Set to true if you don't want to set image from Content.
});
/**
* Determines which image sizes we'll loop through to get an appropriate image.
*
* @param unsigned array - The array of image sizes to loop through. Default array( 'full', 'large', 'medium_large' )
*/
add_filter( 'rank_math/opengraph/image_sizes', function( $sizes ) {
return $sizes;
});
این فیلتر به شما امکان می دهد متا تگ های اجتماعی خاص را به صورت پویا در قسمت جلویی تغییر دهید.
/**
* Allow developers to change the content of specific social meta tags.
*
* The dynamic part of the hook name. $network, is the network slug
* and $og_property, is the property which we are outputting.
*
* @param string $content The content of the property.
*/
add_filter( "rank_math/opengraph/{$network}/$og_property", function( $content ) {
return $content;
});
/**
* Allow changing the Twitter Card type as output in the Twitter card.
*
* @param string $type
*/
add_filter( 'rank_math/opengraph/twitter/card_type', function( $type ) {
return $type;
});
/**
* Hook to remove og:tags
*/
add_action( 'rank_math/head', function() {
remove_all_actions( 'rank_math/opengraph/facebook' );
remove_all_actions( 'rank_math/opengraph/twitter' );
});
/**
* Allow developers to prevent the output of the price in the OpenGraph tags.
*
* @param bool unsigned Defaults to true.
*/
add_filter( 'rank_math/woocommerce/og_price', '__return_false' );
از این فیلتر برای حذف تگ های product:price:amount و product:price:currency متا استفاده کنید.
/**
* Filter: Change the text to calculate the time to read.
*
* @param string $content The content of the post.
*/
add_filter('rank_math/frontend/time_to_read_content', function ($post_content) {
return wp_strip_all_tags($post_content);
});
/**
* Filter: Change the words per minute to calculate the time to read.
*/
add_filter( 'rank_math/frontend/time_to_read_wpm', function(){
return 200; //Words Per Minute
} );
/**
* Filter: 'rank_math/social/create_overlay_image' - Change the create_overlay_image arguments.
*/
add_filter('rank_math/social/create_overlay_image', function ($args) {
return $args;
}, ۱۰, ۱);
/**
* Code to remove json+ld data
*
*/
add_action( 'rank_math/head', function() {
global $wp_filter;
if ( isset( $wp_filter["rank_math/json_ld"] ) ) {
unset( $wp_filter["rank_math/json_ld"] );
}
});
/**
* Collect data to output in JSON-LD.
*
* @param array $unsigned An array of data to output in json-ld.
* @param JsonLD $unsigned JsonLD instance.
*/
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
return [];
}, ۹۹, ۲);
/**
* Allow developer to disable the breadcrumb json-ld output.
*
* @param bool $unsigned Default: true
*/
add_filter( 'rank_math/json_ld/breadcrumbs_enabled', '__return_false' );
/**
* Allow developers to remove snippet data from Taxonomies.
*
* @param bool $unsigned Default: false
* @param string $unsigned Taxonomy Name
*/
add_filter( 'rank_math/snippet/remove_taxonomy_data', function( $value, $taxonomy ) {
return $value; // true or false
}, ۱۰, ۲);
/**
* Filter: Allow disabling the review display.
*
* @param bool $return true to disable.
*/
add_filter( 'rank_math/snippet/review/hide_data', '__return_true' );
/**
* Filter to change the review display location
*
* @param string $location top, bottom, both or custom.
*/
add_filter( 'rank_math/snippet/review/location', function( $location, $taxonomy ) {
return $location;
});
/**
* Filter to change review editor's choice text
*
* @param string $text Default Editor's choice.
*/
add_filter( 'rank_math/review/text', function( $text ) {
return $text;
});
/**
* Filter to change review snippet HTML
*
* @param string $html.
*/
add_filter( 'rank_math/snippet/html', function( $html ) {
return $html;
});
/**
* Filter to remove Schema Data from Posts.
* Replace $schema_type with schema name like article, review, etc.
* @param bool $value true/false Default false
* @param array $parts Post Data
* @param array $data Schema Data
*
* @return bool
*/
add_filter( "rank_math/snippet/rich_snippet_{$schema_type}", function( $value, $parts, $data ) {
return true;
}, ۱۰, ۳ );
/**
* Filter to change the schema data.
* Replace $schema_type with schema name like article, review, etc.
* @param array $entity Snippet Data
* @return array
*/
add_filter( "rank_math/snippet/rich_snippet_{$schema}_entity", function( $entity ) {
return $entity;
});
/**
* Filter to add Brand Name for Products.
*
* @param array $entity Snippet Data
* @return array
*/
add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
$entity['brand']['@type'] = 'Brand';
$entity['brand']['name'] = 'Rank Math';
return $entity;
});
این فیلتر زمانی مفید است که نویسندگان مهمان دارید.
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if ( ! isset( $data['ProfilePage'] ) ) {
return $data;
}
global $post;
$author_id = is_singular() ? $post->post_author : get_the_author_meta( 'ID' );
if ( in_array( intval( $author_id ), [ 1, 2, 3 ], true ) ) { unset($data['ProfilePage']['worksFor']); }
return $data;
}, ۹۹, ۲);
/**
* Filter to change the rank_math_rich_snippet shortcode content.
*
* @param string $shortcode_html
*/
add_filter( 'rank_math/snippet/html', function( $shortcode_html ) {
return $shortcode_html;
} );
اگر نویسنده پست برای شرکت شما کار نمی کند یا نویسنده مهمان است، از این فیلتر برای حذف worksForویژگی از موجودیت نویسنده استفاده کنید.
/**
* Filter to remove worksFor from the Author Entity.
*/
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if ( ! isset( $data['ProfilePage'] ) ) {
return $data;
}
global $post;
$author_id = is_singular() ? $post->post_author : get_the_author_meta( 'ID' );
if ( in_array( $author_id, [ 1, 2, 3 ], true ) ) {
unset($data['ProfilePage']['worksFor']);
}
return $data;
}, ۹۹, ۲);
/**
* Filter the attachment title of the video thumbnail.
*
* @param string $attachment_title The attachment title of the video thumbnail.
* @param array $data The video data.
* @param object $post The post object.
*/
add_filter('rank_math/schema/video_thumbnail_attachment_title', function ($attachment_title, $data, $post) {
return $attachment_title;
}, ۱۰, ۳ );
/**
* Filter the filename of the video thumbnail.
*
* @param string $filename The filename of the video thumbnail.
* @param array $data The video data.
* @param object $post The post object.
*/
add_filter('rank_math/schema/video_thumbnail_filename', function ($filename, $data, $post) {
return $filename;
}, ۱۰, ۳ );
/**
* Filter: Allow changing the Pros & Cons labels.
*
* @param array $labels {
* @type string $pros Pros label.
* @type string $cons Cons label.
* }
*/
add_filter( 'rank_math/schema/review_notes_labels', function( $labels ) {
return $labels;
});
/**
* Filter to change parameters for the Front End SEO Score output.
* Available parameters are: 'template', 'backlink', 'post_id', 'class'.
*
* @param array $args Parameters array.
* @return array
*/
add_filter( "rank_math/frontend/seo_score/args", function( $args ) {
return $args;
});
/**
* Filter to change HTML output for the Front End SEO Score function.
*
* @param string $html HTML output.
* @param array $args Function parameters.
* @param string $score calculated SEO score.
* @return string
*/
add_filter( "rank_math/frontend/seo_score/html", function( $html, $args, $score ) {
return $html;
}, ۱۰, ۳);
/**
* Filter to change the backlink inside the Front End SEO Score output.
*
* @param string $backlink Backlink HTML.
* @return string
*/
add_filter( "rank_math/frontend/seo_score/backlink", function( $backlink ) {
return $backlink;
});
/**
* Filter to hide SEO SCcore
*/
add_filter( 'rank_math/show_score', '__return_false' );
/**
* Allow developers to change number of redirections to process at once.
*
* @param int $number
*/
add_filter( 'rank_math/redirections/pastedContent', function( $number ) {
return $number;
});
/**
* Disable appending the query string in the redirection URL.
*
* @param int $number
*/
add_filter( 'rank_math/redirection/add_query_string', '__return_false' );
هنگامی که گزینه Remove base یا Remove category base برای محصولات WooCommerce فعال است، از این فیلتر برای غیرفعال کردن تغییر مسیر محصول سفارشی استفاده کنید .
/**
* Filter to disable custom product redirection.
*/
add_filter( 'rank_math/woocommerce/product_redirection', '__return_false' );
/**
* Filter to strip leading slashes for Regex redirections
*/
add_filter( 'rank_math/redirection/get_clean_pattern', function( $cleaned, $pattern, $comparison ) {
if ( $comparison === 'regex' ) {
$cleaned = '@' . stripslashes( ltrim( $pattern, '/' ) ) . '@';
}
return $cleaned;
}, ۱۰, ۳ );
از این فیلتر برای حذف ادغام رنک مث از نوار کناری گوتنبرگ و اضافه کردن متا باکس های قدیمی در زیر ناحیه محتوا استفاده کنید.
/**
* Disable Gutenberg Sidebar Integration
*/
add_filter( 'rank_math/gutenberg/enabled', '__return_false' );
/**
* Filter to add meta keys for enqueueing data in the Gutenberg
*/
add_filter( 'rank_math/metabox/{$type}/meta_keys', function( $keys ) {
$keys['facebookTitle'] = 'facebook_title';
return $args;
} );
هنگام استفاده از این متاکلید، لطفاً آن را با پیشوند اضافه کنیدrank_math_
/**
* Filter to add metadata for enqueueing for Gutenberg use
*/
add_filter( 'rank_math/metabox/{$type}/values', function( $values, $screen ) {
$object_id = $screen->get_object_id();
$object_type = $screen->get_object_type();
$values['videoSitemap'] = [
'robots' => $screen->get_meta( $object_type, $object_id, 'rank_math_news_sitemap_robots' ),
'genres' => $screen->get_meta( $object_type, $object_id, 'rank_math_news_sitemap_genres' ),
'keywords' => $screen->get_meta( $object_type, $object_id, 'rank_math_news_sitemap_keywords' ),
'stockTickers' => $screen->get_meta( $object_type, $object_id, 'rank_math_news_sitemap_stock_tickers' ),
];
return $values;
} );
$typeمی تواند پست، مدت و کاربر باشد.
/**
* Filter to hide SEO Tab in the Elementor Editor.
*/
add_filter( 'rank_math/elementor/add_seo_tab', '__return_false' );
/**
* Filter to hide SEO Tab in the Divi Editor.
*/
add_filter( 'rank_math/divi/add_seo_tab', '__return_false' );
/**
* Redirect the attachment to its parent post.
*
* @param string $redirect URL as calculated for redirection.
*/
add_filter( 'rank_math/frontend/attachment/redirect_url', function( $redirect ) {
return $redirect;
});
/**
* Let developers determine hether or not to add rel="nofollow" to the links added by Rank Math to the RSS feed. This defaults to true.
*
* @param bool $unsigned To allow or not to follow the links in RSS feed, defaults to true.
*/
add_filter( 'rank_math/frontend/rss/nofollow_links', '__return_false' );
/**
* Show or hide the RSS footer dynamically.
*
* @param bool $show_embed Whether RSS footer should be shown or not.
* @param string $context Indicated the context of the RSS content - whether 'full' or 'excerpt'.
*/
add_filter( 'rank_math/frontend/rss/include_footer', function( $bool, $context) {
return $bool;
});
/**
* Filter code to change content before RSS feed item
*
* @param string $content The content set in Settings.
*/
add_filter( 'rank_math/frontend/rss/before_content', function( $content ) {
return $content ;
});
/**
* Filter code to change content after RSS feed item
*
* @param string $content The content set in Settings.
*/
add_filter( 'rank_math/frontend/rss/after_content', function( $content ) {
return $content ;
});
/**
* Filter code to remove noopener rel from external links.
*/
add_filter( 'rank_math/noopener', '__return_false');
/**
* Filter to allow disabling of the primary term feature.
*
* @param bool $return True to disable.
*/
add_filter( 'rank_math/admin/disable_primary_term', '__return_true' );
/**
* Filter: 'rank_math_remove_reply_to_com' - Allow or disable the Rank Math feature that removes `?replytocom`
* query parameters from URLs.
* @param bool $return True to remove, false not to remove.
*/
add_filter( 'rank_math/frontend/remove_reply_to_com', '__return_false');
/**
* Filter: Remove/modify schema data.
*
* @param array $return Array of json-ld data.
*/
add_filter( 'rank_math/json_ld', function( $data, $json ) {
if ( is_home() && isset( $data['Blog'] ) ) { // Remove Blog Snippet from homepage.
unset( $data['Blog'] );
}
return $data;
}
/**
* Filter: Prevent Rank Math from changing admin_footer_text.
*/
add_action( 'rank_math/whitelabel', '__return_true');
/**
* Filter to add/remove noopener attribute based on a domain.
*
* @param string $domain The domain in question.
*
* @return boolean
*/
add_filter( 'rank_math/noopener/domain1', function( $domain ) {
$exclude = [
'github.com',
'google.com',
];
if ( in_array( $domain, $exclude ) ) {
return false;
}
return true;
});
/**
* Filter to remove Rank Math data from the database
*/
add_filter( 'rank_math_clear_data_on_uninstall', '__return_true' );
کد بالا را در فایل تم اضافه functions.phpکنید (کد بالا در فایل کار نخواهد کرد rank-math.php)
افزونه رنک مث را غیرفعال و حذف کنید
/**
* Allows filtering of the search URL.
*
* @param string $search_url The search URL for this site with a `{search_term_string}` variable.
*/
add_filter( 'rank_math/json_ld/search_url', function( $url ) {
return $url;
});
/**
* Filter to add plugins to the TOC list.
*
* @param array TOC plugins.
*/
add_filter( 'rank_math/researches/toc_plugins', function( $toc_plugins ) {
$toc_plugins['plugin-directory/plugin-filename.php'] = 'Plugin Name';
return $toc_plugins;
});
/**
* Filter to remove `rank-math-link` class from the frontend content links
*/
add_filter( 'rank_math/link/remove_class', '__return_true' );
/**
* Filter to hide Analytics Stats bar from the frontend
*/
add_filter( 'rank_math/analytics/frontend_stats', '__return_false' );
مقاله آمار و ابزار رنک مث میتواند برای شما مفید باشد.
و همین! امیدواریم این مقاله برای استفاده از فیلترها و قلاب های مختلف موجود با رنک مث مفید بوده باشد. اگر در مورد استفاده از این فیلترها سؤالی دارید یا به کمک نیاز دارید، مستقیماً از اینجا با تیم پشتیبانی پارس اوستا در تماس باشید و ما همیشه برای کمک در اینجا هستیم.