How to add noindex to category pages until category have minimum 10 posts

#420001
  • Resolved Manav Kalra
    Rank Math free

    Hello there,

    I am using your plugin from past 1 year and I am really amazed. I need one help if possible. I have created a new website based on biography of people, where we have to create lots of categories according to people profession like actor, doctor, player etc. , sometimes some categories have only 1-2 posts and we don’t want these categories to get indexed in google as google will treat it as thin content and this will put negative impact on our website. We have to create daily many categories as we are writing about people there are many professions so its not possible to add noindex,index to categories and later add index,follow manually.

    So, basically I need a code, so every new category have “noindex, follow” until a number of posts like 10 posts and when 10 posts added in that category meta robots automatically changes to “index, follow”. For eg: we created new category today named as “actor” , so this category will have “noindex, follow” on robots until have 10 posts in it.

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

    Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.

    Kindly refer to this filter code I made:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
      $category = get_queried_object();
    
    	if($category->count >= 10){
    		$robots["index"] = 'index';
    		$robots["follow"] = 'follow';
    	}
    	return $robots;
    });

    You also need to ensure that your categories are set to noindex by default to complete the logic.

    Let us know how that goes on your end.

    Looking forward to helping you.

    Hi Jeremy,

    It works perfect. One last thing. What I need to add extra in this code to apply this code to category as well as tag both in single code ?

    Hello,

    The code will work for both categories and tags. You don’t need to make any changes to it.

    Hope this helps. Let us know if you need any other assistance.

    Thanks.

    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 ‘How to add noindex to category pages until category have minimum 10 posts’ is closed to new replies.