Filter noindex status of single post?

#523381
  • Resolved Andrew Cox
    Rank Math free

    Hi there. Thanks for a great plugin. Is there a filter that would allow me to programmatically change the index status of a single post? I realize I can change the value of the rank_math_robots meta field, but I’m looking to override that setting altogether. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    You can easily set noindex your post from the Advanced Tab in Rank Math meta box. However, if you want to use filter to set the post noindex then you can use the following one:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	global $post;
    	if( $post->ID == 1 ){		
    	    $robots["index"] = 'noindex';
                $robots["follow"] = 'nofollow';
    	}
    	return $robots;
    });
    

    Change the post ID 1 with your actual post ID.

    Here is a guide you can follow to add the filter:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps and please don’t hesitate to let us know if you have any other questions.

    Thank you.

    That’s what I was looking for. Much appreciated.

    Hello,

    Glad that helped.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Filter noindex status of single post?’ is closed to new replies.