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. Use the Description from Global Setting, if the description is missing in the Post metabox:
/**
* 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;
});
5. Filter to change robots data.
Use this filter to change robots meta added by Rank Math dynamically on the front-end.
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
return $robots;
});
6. 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;
});
7. 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' );
8. 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' );
9. Filter to change adjacent link output.
/**
* 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;
});
10. Filter to add the Keywords meta tag
/**
* Add <meta name="keywords" content="focus keywords">.
*/
add_filter( 'rank_math/frontend/show_keywords', '__return_true');
11. Filter to change the meta keywords
/**
* Allow changing the meta keywords from the default Focus Keywords.
*
* @param string $keywords Keywords.
*/
add_filter( 'rank_math/frontend/keywords', function( $keywords ) {
return $keywords;
});
12. Filter to Allow Shortcodes in the Meta Data
/**
* Allow shortcodes in the Meta Data.
*/
add_filter( 'rank_math/paper/auto_generated_description/apply_shortcode', '__return_true' );
13. Filter to allow shortcodes in the Product Schema description
/**
* Filter to allow shortcodes in the Product schema description.
*/
add_filter( 'rank_math/product_description/apply_shortcode', '__return_true' );