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' );
3. Filter to allow RSS footer to be dynamically shown/hidden in an RSS feed item
/**
* 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/admin/disable_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;
} );
10. Filter to prevent Rank Math from changing admin_footer_text
/**
* 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/domain', 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' );
- Add above code in the theme’s
functions.php
file (the above code will not work in therank-math.php
file) - Deactivate and delete the Rank Math plugin
13. Filter to customize the Search URL for Sitelinks Searchbox
/**
* 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;
});
14. Filter to add plugins to the Table of Content List
/**
* 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;
});
15. Filter to remove rank-math-link
class from the frontend content links
/**
* Filter to remove `rank-math-link` class from the frontend content links
*/
add_filter( 'rank_math/link/remove_class', '__return_true' );
16. Filter to hide Analytics Stats Bar from the frontend
/**
* Filter to hide Analytics Stats bar from the frontend
*/
add_filter( 'rank_math/analytics/frontend_stats', '__return_false' );
17. Filter to create Analytics debug log
/**
* Filter to create Analytics debug.log file
*/
add_filter( 'rank_math/analytics/log_response', '__return_true' );
18. Filter to modify the content passed to the Link Counter
/**
* Filter to modify the content passed to the Link Counter.
*
* @param string $content Post content.
* @param int $post_id Post ID.
*/
add_filter( 'rank_math/links/content', function ( $content, $post_id) {
return $content;
}, 10, 2 );
19. Filter to prevent Link Counter from processing the post
/**
* Filter to prevent processing the post.
*
* @param boolean $value Whether to process the post.
* @param WP_POST $post The Post object.
*/
add_filter( 'rank_math/links/process_post', function( $value, $post ) {
return false;
}, 10, 2 );
20. Filter to allow editing robots.txt & htaccess data
This filter lets you allow/disallow editing robots.txt and htaccess from Rank Math General Settings regardless of the value set for the DISALLOW_FILE_EDIT
and DISALLOW_FILE_MODS
.
/**
* Allow editing the robots.txt & htaccess data.
*
* @param bool Can edit the robots & htacess data.
*/
add_filter( 'rank_math/can_edit_file', '__return_true' );
21. Filter to remove nofollow tag from specific external links
Note: This filter works only for nofollow tags added using Rank Math or not for manually added tags.
/**
* Allow developers to remove nofollow tag from specific external links
*
* @param $add_no_follow bool Should add no follow attribute.
* @param string $href The URL string for the external link.
*/
add_filter('rank_math/nofollow/url', function ( $add_no_follow, $href ) {
if ( $href === 'https://wordpress.org/gutenberg/') { // maybe in_array compare
return false;
}
return $add_no_follow;
}, 10, 2);
22. Filter to disable cache used in the plugin
/**
* Filter to disable cache used in the plugin.
*/
add_filter( 'rank_math/cache/enabled', '__return_false' );
23. Filter to Modify Rank Math JSON data
/**
* Filter to modify Rank Math JSON data.
*/
add_filter( 'rank_math/json_data', function( $data ) {
$data['testing'] = wp_create_nonce( 'rank-math' );
return $data;
} );