Hello, we apologize for the inconvenience. At the moment, Rank Math does not have a built-in feature to set different title formats for different categories. However, you can achieve this by using custom code and filters. You can use the rank_math/paper_type
filter to change the paper type based on the category. Here’s an example of how you can use this filter:
add_filter( 'rank_math/paper_type', function( $paper_type ) {
if ( is_category( 'category-1' ) ) {
$paper_type = '%title% %sep% %sitename%';
} elseif ( is_category( 'category-2' ) ) {
$paper_type = '%title% %sep% %category% %sep% %sitename%';
}
return $paper_type;
});
You can add this code to your theme’s functions.php
file or preferably use a child theme or a custom plugin to avoid losing your changes when you update your theme. If you need further assistance with this, please feel free to ask.
Sources:
Rank Math ‘Titles and Meta’ Options and Settings
Is Rank Math Compatible With Crocoblock? » Rank Math
So, here’s what I did:
1. Installed RankMath
2. Followed the standard configuration.
3. Did not change any specific settings.
4. Added the code to functions.php(by modifying as per my requirement – you know changing the category slug)
But its not working. The title still follows the format defined at the plugin settings (Titles and Meta Section), instead of following the format specified in the filter.
Also, I am not able find any documentation for paper_type
filter. What am I doing wrong?
Hello,
Thank you for your patience.
Please update the filter to this one instead to achieve that:
/**
* Filter to change the page title.
*
* @param string $title
*/
add_filter( 'rank_math/frontend/title', function( $title ) {
global $post;
$category = get_the_category($post->ID);
if ( $category = 'category-1' ) {
$title = '%title% %sep% %sitename%';
}
if ( $category = 'category-2') {
$title = '%title% %sep% %category% %sep% %sitename%';
}
return $title;
});
You may modify the filter to change the actual category name.
Hope that helps.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.