Hello,
Thank you for contacting Rank Math today.
Unfortunately Rank math only has the option to noindex all posts under a specific post type or all category pages. However, you can modify the following filter to work for you
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
global $post;
// filter for only a specific post type
if(get_post_type() == "your_post_type_name_here"){
$robots['index'] = "noindex";
$robots['follow'] = "nofollow";
return $robots;
}
return $robots;
});
Looking forward to helping you. Thank you.
​​​​​​
I can’t use your provided code to NOINDEX/NOFOLLOW for the category because it’s a category and not a Post type. What do I do for categories?
Hello,
You would need to modify the previous filter to also check for categories (or if you use custom categories, for terms).
These functions could be useful for doing those changes:
https://developer.wordpress.org/reference/functions/get_the_terms/
https://developer.wordpress.org/reference/functions/get_the_category/
Looking forward to help you.
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.