1. Home
  2. Knowledge Base
  3. SEO Suite
  4. Rank Math SEO Filters and Hooks for Developers

Rank Math SEO Filters and Hooks for Developers

We have incorporated various hooks and filters in Rank Math SEO plugin that developers can use to interact with data output by Rank Math. You can control Rank Math data from within your themes/plugins.

Settings

1. Filter to add/remove tabs in Rank Math Metabox.

Use this filter add new tabs into the Meta Box added by Rank Math below every post/page in WordPress Editor.

/**
 * Allow developers to add new tabs into main metabox.
 *
 * @param array $tabs Array of tabs.
 */
add_filter( 'rank_math/metabox/tabs', function( $tabs) {
	return $tabs;
});

2. Filter to add/remove section into the General Settings option panel.

This filter allows you to add or remove a section from the general settings options panel of Rank Math plugin.

/**
 * Allow developers to add new section into general setting option panel.
 *
 * @param array $tabs
 */
add_filter( 'rank_math/settings/general', function( $tabs) {
	return $tabs;
});

3. Filter to add/remove section into the Title Settings option panel.

You can add or remove a custom section to or from the Title Settings option panel with this setting.

/**
 * Allow developers to add new section into general setting option panel.
 *
 * @param array $tabs
 */
add_filter( 'rank_math/settings/title', function( $tabs) {
	return $tabs;
});

4. Filter to allow developers to add option fields to check against update. And if updated, flush the rewrite rules

/**
 * 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;
});

5. Filter to allow developers to add new tabs into the options panel.

/**
 * 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;
});

6. Filter to add/update/remove Content Analysis test.

/**
 * 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 $tabs;
}, 10, 2 );

7. Filter to change number of items to import per run. Used when importing data from other plugins

/**
 * 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;
});

8. Filter to add/remove help content tabs on Help & Support Page.

/**
 * Add new help content tabs on help and support page.
 *
 * @param array $help_content
 */
add_filter( 'rank_math/importers/items_per_page', function( $help_content ) {
	return $help_content;
});

9. Filter to add/remove item from Admin Bar node.

Add or remove an item from the WordPress admin-bar menu that Rank Math adds to the frontend of your WordPress website.

/**
 * 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;
});

10. Add Default value for General Settings during plugin installation.

Set a default value for general settings when Rank Math is installed on a WP website.

/**
 * 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;
});

11. Add Default value for Title Settings during plugin installation.

/**
 * 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;
});

12. Add Default value for Sitemap Settings during plugin installation.

/**
 * 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;
});

13. Allow developers to add/remove/change Modules.

/**
 * 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;
});

14. Filter to change Author base.

Use this filter to change the URL base for author archives.

/**
 * Allow developers to change the author base.
 *
 * @param string $base The author base.
 */
add_filter( 'rank_math/author_base', function( $base ) {
	return $base;
});

15. Filter to change the address part format.

/**
 * 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;
});

16. Filter to change Post type icons in options panel.

/**
 * 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;
});

17. Filter to change Taxonomy icons in options panel.

/**
 * Allow developer to change taxonomies icons.
 *
 * @param array $icons Array of available icons.
 */
add_filter( 'rank_math/taxonomy_icons', function( $icons ) {
	return $icons;
});

18. Filter to enable/disable overlay icon option in Social Tab in Post Settings.

/**
 * 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;
}, 10, 2 );
/**
 * 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;
}, 10, 2 );

20. Filter to set default Snippet type for post type.

/**
 * 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;
}, 10, 2 );

21. Filter to set default Snippet Article type for post type.

/**
 * 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;
}, 10, 2 );

22. Filter to add custom variable replacements.

/**
 * Filter to add custom variables
 */
add_filter( 'rank_math/vars/replacements', function( $vars ) {
	return $vars;
});

23. Filter to show/hide SEO Metabox.

/**
 * Filter to show/hide SEO Metabox.
 */
add_filter( 'rank_math/metabox/add_seo_metabox', function( $default ) {
	return $default;
});

24. Filter to change Separator %sep%.

/**
 * Filter to change Separator %sep%.
 */
add_filter( 'rank_math/settings/title_separator', function( $sep ) {
	return $sep;
});

Sitemap

1. Filter to change Sitemap Cache directory.

/**
 * Filter XML sitemap cache directory.
 *
 * @param string $unsigned Default cache directory
 */
add_filter( 'rank_math/sitemap/cache_directory', function( $directory) {
	return $directory;
});

2. Filter to enable/disable Sitemap caching.

/**
 * 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');

3. Filter to exclude post type from the 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;
}, 10, 2 );

4. Filter sitemap item before it gets added to the sitemap.

/**
 * Filter URL entry before it gets added to the sitemap.
 *
 * @param array  $url  Array of URL parts.
 * @param string $type URL type. Can be user, post or term.
 * @param object $object Data object for the URL.
 */
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
	return $url;
}, 10, 3 );

5. Filter to change/remove archive url, plugin uses in th XML Sitemap.

/**
 * 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;
}, 10, 2 );

6. Filter to change/remove Post URL, plugin uses in the sitemap.

/**
 * 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;
}, 10, 2 );

7. Filter to exclude taxonomy from Sitemap.

/**
 * 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;
}, 10, 2 );

8. Filter to exclude empty terms from Sitemap.

/**
 * 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;
}, 10, 2 );

9. Filter to remove/change images included for the post in XML sitemap.

/**
 * 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;
}, 10, 2);

10. Filter to Remove Sitemap credit.

/**
 * Filter to remove sitemap credit.
 *
 * @param boolean Defaults to false.
 */
add_filter( 'rank_math/sitemap/remove_credit', '__return_true');

11. Filter to Add Extra URLs in the Sitemap

/**
 * 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() {
  
});
function rank_math_add_custom_dynamic_url( $urls ) {
    $urls .= '
        http://www.mysite.com/dynamic-category1/
        2019-02-22T18:02:24+00:00
    ';

    $urls .= '
        http://www.mysite.com/dynamic-category2/
        2019-02-22T18:02:24+00:00
    ';

    return $urls;
}

12. Filter to add Locations KML file in the Sitemap

/**
 * Filter to remove Locations KML file from sitemap
 */
add_filter( 'rank_math/sitemap/locations', function() {
    return true;
});

1. Filter to change the Breadcrumb Settings.

Add these lines to the theme’s functions.php file

/**
 * 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;
});

2. Filter to change Breadcrumb Strings.

Add these lines to the theme’s functions.php file

/**
 * 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;
});

3. Filter to change Breadcrumb args.

Add these lines to the theme’s functions.php file

/**
 * 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;
});

4. Filter to change the Breadcrumb HTML.

Add these lines to the theme’s functions.php file

/**
 * 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;
}, 10, 3);

5. Filter to change the primary term output of the breadcrumbs class.

Add these lines to the theme’s functions.php file

/**
 * 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;
}, 10, 2 );

6. Filter to change/remove breadcrumb items.

Add these lines to the theme’s functions.php file

/**
 * 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;
}, 10, 2);

7. Filter to change/remove breadcrumb items from Breadcrumb Snippet.

Add these lines to the theme’s functions.php file

/**
 * Allow changing Breadcrumb elements in BreadcrumbList snippet
 *
 * @param array $entity Breadcrumb entity
 */
add_filter( 'rank_math/snippet/breadcrumb', function( $entity ) {
	return $entity;
});

Meta Data

1. Filter to change the Title.

/**
 * Filter to change the page title.
 * 
 * @param string $title
 */
add_filter( 'rank_math/frontend/title', function( $title ) {
	return $title;
});

2. The code to move the title inside the Rank Math’s meta box

/**
 * 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 );
});

3. Filter to change the meta description.

/**
 * 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;
});

4. Filter to change robots data.

/**
 * Allows filtering of the robots meta data.
 *
 * @param array $robots The meta robots directives.
 */
add_filter( 'rank_math/frontend/robots', function( $robots ) {
	return $robots;
});

5. Filter to change Canonical URL.

/**
 * Allow changing of the canonical URL.
 *
 * @param string $canonical The canonical URL.
 */
add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
	return $canonical;
});

6. Filter to remove plugin credit notice added to the page source.

/**
 * Filter to remove the plugin credit notice added to the source.
 *
 */
add_filter( 'rank_math/frontend/remove_credit_notice', '__return_true' );

7. Filter to disable adjacent links ( next/prev ).

/**
 * 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( "frontend/{$rel}_rel_link", function( $link ) {
	return $link;
});

OpenGraph

1. Filter to change OpenGraph Type ( og:type ).

/**
 * 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;
});

2. Filter to change OpenGraph URL ( og:url ).

/**
 * 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;
});

2. Filter to remove Twitter tags from page output.

/**
 * Allows changing the Twitter Card type as output in the Twitter card.
 *
 * @param string $type
 */
add_filter( 'rank_math/opengraph/twitter_card', '__return_false' );

3. Filter to change OpenGraph Image.

/**
 * 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;
});

3. Filter to allow developers to add additional images.

/**
 * 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;
});

4. Filter to prevent setting default image in OpenGraph.

/**
 * 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' );

5. Filter to prevent setting image from content when image is not added in OpenGraph.

/**
 * 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.
});

6. Filter to determine image size to show in og:image, twitter:image.

/**
 * 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;
});

7. Filter to change specific social meta tags.

/**
 * 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;
});

8. Filter to change twitter card type.

/**
 * 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;
});

9. A Hook to remove OpenGraph tags.

/**
 * 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' );
});

Rich Snippets

1. Code to remove json+ld data

/**
 * 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"] );
	}
});

2. Filter to extend json+ld data

/**
 * 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 [];
}, 10, 2);

3. Filter to remove BreadcrumbList Schema

/**
 * Allow developer to disable the breadcrumb json-ld output.
 *
 * @param bool $unsigned Default: true
 */
add_filter( 'rank_math/json_ld/breadcrumbs_enabled', '__return_false' );

4. Filter to remove CollectionPage Schema on Taxonomy Pages

/**
 * 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
}, 10, 2);

5. Filter to disable the Review Display on the frontend

/**
 * Filter: Allow disabling the review display.
 *
 * @param bool $return true to disable.
 */
add_filter( 'rank_math/snippet/review/hide_data', '__return_true' );

6. Filter to change the Review Display location

/**
 * 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;
});

7. Filter to change the Review Editor’s choice text

/**
 * Filter to change review display location
 *
 * @param string $text Default Editor's choice.
 */
add_filter( 'rank_math/review/text', function( $text ) {
	return $text;
});

8. Filter to change the Review Snippet HTML

/**
 * Filter to change review display location
 *
 * @param string $html.
 */
add_filter( 'rank_math/review/html', function( $html ) {
	return $html;
});

9. Filter to remove Schema Data from Posts

/**
 * Filter to Short-circuit Schema if a 3rd party is interested in generating their own data.
 * Replace $schmea_type with schema name like article, review, etc.
 * @param bool  $value true/false Default false
 * @param array $parts Post Data
 * @param array $data  Schmea Data
 * 
 * @return bool
 */
add_filter( "rank_math/snippet/rich_snippet_{$schema_type}", function( $value, $parts, $data ) {
	return true;
}, 10, 3 );

10. Filter to change Posts Schema data

/**
 * Filter to Short-circuit Schema if a 3rd party is interested in generating their own data.
 * Replace $schmea_type with schema name like article, review, etc.
 * @param array $entity Snippet Data
 * @return array
 */
add_filter( "rank_math/snippet/rich_snippet_{$schema_type}", function( $entity ) {
	return $entity;
});

11. Add Brand Name for Products

/**
 * 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'] = 'Rank Math;
    return $entity;
});

SEO Score

1. Filter to change parameters for the Front End SEO Score output.

/**
 * 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( "frontend/seo_score/args", function( $args ) {
	return $args;
});

2. Filter to change HTML output for the Front End SEO Score function.

/**
 * 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( "frontend/seo_score/html", function( $html, $args, $score ) {
	return $html;
}, 10, 3);
/**
 * Filter to change the backlink inside the Front End SEO Score output.
 *
 * @param string $backlink Backlink HTML.
 * @return string
 */
add_filter( "frontend/seo_score/backlink", function( $backlink ) {
	return $backlink;
});

Misc

1. Filter to change redirect_url of Redirect attachment to its parent post.

/**
 * 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;
});

2. Filter to remove the nofollow rel tag from RSS links

/**
 * 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;
});

4. Filter to add/remove content before RSS feed item.

/**
 * 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 ;
});

5. Filter to add/remove content after RSS feed item.

/**
 * 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 ;
});

6. Filter to remove rel=”noopener” from external links.

/**
 * Filter code to remove noopener rel from external links.
 */
add_filter( 'rank_math/noopener', '__return_false');

7. Filter to disable primary term feature.

/**
 * Filter to allow disabling of the primary term feature.
 *
 * @param bool $return True to disable.
 */
add_filter( 'rank_math/primary_term', '__return_true');

8. Filter to remove `?replytocom` query parameters from URLs

/**
 * 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');

9. Filter to remove Blog Snippet on homepage

/**
 * 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');

11. Remove noopener attribute based on a domain

/**
 * 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;
});

12. Remove everything related to Rank Math from Database

/**
 * Filter to remove Rank Math data from the database
 */
add_filter( 'rank_math_clear_data_on_uninstall', '__return_true' );

13. Change number of redirections to process at once

/**
 * Allow developers to change number of redirections to process at once.
 *
 * @param int $number
 */
add_filter( 'rank_math/redirections/pastedContent', function( $number ) {
	return $number;
});
/**
 * 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;
});

Was this article helpful?

Related Articles