Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
Please add the following filter to your theme’s functions.php file:
/**
* Filter to set noindex to specific categories
*/
add_filter( 'rank_math/frontend/robots', function ( $robots ) {
$categories = array_map( function ( $category ) {
return $category->slug;
}, get_the_category() );
//Replace your_category with your category slug.
if ( in_array( 'your_category', $categories ) ) {
unset( $robots['index'] );
$robots['noindex'] = 'noindex';
}
return $robots;
} );
You can find the slug of each category against their category name. Copy and paste the slug in the above code snippet.
Note: Once you’ve added the code snippet to set noindex, any attempt to override a specific post inside the WordPress editor by setting index robots meta tag will not work. The post will continue to show noindex in the front-end until you remove the code snippet.
We hope that answers your question. Please don’t hesitate to contact us again if you need further assistance with anything else.
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.