Hello,
Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.
In this case, you may need to set the robots in Rank Math > Titles & Meta to No Index and add a filter to set the archive page of your custom post type to index and follow:
https://rankmath.com/kb/filters-hooks-api-developer/#change-robots-meta
Here’s a sample filter you can use and customize (the archive page in this sample is /cpt-archive/):
add_filter( 'rank_math/frontend/robots', function( $robots ) {
if(is_post_type_archive('cpt-archive')){
$robots["noindex] = 'index';
$robots["nofollow"] = 'follow';
}
return $robots;
});
The filter should be added to your active theme’s functions.php file. Here’s another way to apply the filter using the rankmath.php file:
https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php
Let us know how this goes.
Thank you.
Thank you for sharing this! I was looking for a solution for this. One thing I noticed is that the code above is slightly off. It should be like below. Notice the $robots[“index”] and $robots[“follow”]. Thank you!
add_filter( 'rank_math/frontend/robots', function( $robots ) {
if(is_post_type_archive('cpt-archive')){
$robots["index"] = 'index';
$robots["follow"] = 'follow';
}
return $robots;
});
Hello,
I am glad that you have fixed it and we are happy that we could address your concern.
If you have further issues with our plugin, just ask away. We are here to help.
Thank you.