Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
I can suggest that you create some code to modify the frontend robots meta only for certain page IDs by making use of the following filter:
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
return $robots;
});
I hope this info helps. Thank you.
Hi there,
Thanks, but how would I pass in the noindex, noarchive and nosnippet with this filter? Please could you provide the complete code snippet for this.
Thank you
Hello,
Here you have (you will need to modify it to work only in the page IDs you want):
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
$robots['index'] = 'noindex';
$robots['noarchive'] = 'noarchive';
$robots['nosnippet'] = 'nosnippet';
return $robots;
});
Looking forward to help you.
Thanks, if anyone else needs this, this is the final code that works:
/**
* Allows filtering of the robots meta data.
*
* @param array $robots The meta robots directives.
*/
add_filter( 'rank_math/frontend/robots', function( $robots ) {
global $post;
// add your page IDs into the array below
if( is_page( array( 1, 2, 3) ) ) {
// noindex etc
$robots['follow'] = 'nofollow';
$robots['index'] = 'noindex';
$robots['noarchive'] = 'noarchive';
$robots['nosnippet'] = 'nosnippet';
return $robots;
}
return $robots;
});
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.