Auto No Index For Posts In Certain Categories?

#58789
  • Resolved info115
    Rank Math free

    I use a content curation plugin to publish news on my site from various RSS feeds. These feeds are pulled in and saved as Drafts in my wordpress dashboard under a specific category. I want these posts automatically marked ‘No Index / No Follow’. Is this possible? If so, how do I set this up?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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?

    Alberto
    Rank Math business

    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.

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

The ticket ‘Auto No Index For Posts In Certain Categories?’ is closed to new replies.