Google Indexing

#77212
  • Resolved Efeikomwan Obasuyi
    Rank Math free

    Please how do i exclude posts of a particular category from google search result.
    e.g
    Infinix” is a category, all post under it should not be index by google.

    I know i can do it post by post, but that’ll be so stressful. Please how can i automate it?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Alberto
    Rank Math business

    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 categories 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.

    Thanks. But am not a developer. So I guess I should add the above code to my child-theme function right?

    Also, the code seems not to specify the particular category am excluding from google search.

    Please little explanation will help.

    Thanks

    Alberto
    Rank Math business

    Hello,

    That code is a template, you should customize it to fit your needs. We are not able to provide customized code since we are a small team, but I did it for you, you just need to add it at the end of your functions.php file:

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
            if(is_single()){
               $categories = get_the_category();
               foreach( $categories as $category ) {
                    if($category->name=="Infinix"){
                       $robots['index'] = 'noindex';
                       $robots['follow'] = 'follow';
                       break;
                    }
               }
            }
    
    	return $robots;
    });

    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 ‘Google Indexing’ is closed to new replies.