Noindex not working for CPT

#682831
  • Resolved Jason Hodge
    Rank Math free

    I have set a cpt to noindex (global setting is index) but it still shows as index. I have checked the robots.txt and there is no obvious disallow that would prevent it (I even removed /machine-for-sale/ from the file and still did not work.)

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    In this case, you may use and customize this filter to match the post type and set it to noindex:

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
         if(get_post_type() == 'Listings'){ //change Listings word to match the actual CPT name
             $robots['index'] = "noindex";
             $robots['follow'] = "follow";
         }
    	return $robots;
    });

    Here’s how you can add filters/hooks to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how this goes.

    Thank 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 1 replies (of 1 total)

The ticket ‘Noindex not working for CPT’ is closed to new replies.