How to Programmatically Modify Meta Title if using RankMath WordPress Plugin

Sharing is caring!

Normally to modify the WordPress pages' meta title you can use the following filter.
doc ref: https://developer.wordpress.org/reference/hooks/the_title/

add_filter( 'the_title', 'SOME_FUNCTION', 50, 2 );

the callback will receive $post_title, $post_id as arguments.

If you're using RankMath for your SEO stuff you need to use this filter: rank_math/frontend/title to modify the meta title.

add_filter('rank_math/frontend/title', function ($title) {
    global $post; // you can access the current page/post
    $title .= ' Append More Info Here';
    return $title;
});

I didn't have the time to fully investigate why that's the case. Maybe RankMath removes the default hooks to ensure no other plugin is dealing with meta title and description fields to avoid issues.

Subscribe to our newsletter

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

Free Online Store by Go359.com
The new new server is up and running. Enjoy!