Add archive page only to sitemap

#334275
  • Resolved Richardj
    Rank Math free

    I have a custom post type (Trucks). I want to add the archive page for Trucks to my sitemap, but not any of the individual Trucks posts.

    I know I could set noindex on every Truck post, but that would be cumbersome unless there is an option to change the defaults for new posts.

    I could use robots.txt, but I want greater control than that.

    I could create a page that shows the Trucks archive. Would that create any other problems?

    Any other ideas?

    Thanks, Richard

Viewing 1 replies (of 1 total)
  • Azib Yaqoob
    Rank Math business

    Hello,

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

    Please add the following filter to your theme’s functions.php file:

    
    /**
     * Filter to set noindex to specific categories
     */
    add_filter( 'rank_math/frontend/robots', function ( $robots ) {
    	$categories = array_map( function ( $category ) {
    		return $category->slug;
    	}, get_the_category() );
    
    	//Replace your_category with your category slug.
    	if ( in_array( 'your_category', $categories ) ) { 
    		unset( $robots['index'] );
    		$robots['noindex'] = 'noindex';
    	}
    	return $robots;
    } );
    

    You can find the slug of each category against their category name. Copy and paste the slug in the above code snippet.

    Note: Once you’ve added the code snippet to set noindex, any attempt to override a specific post inside the WordPress editor by setting index robots meta tag will not work. The post will continue to show noindex in the front-end until you remove the code snippet.

    We hope that answers your question. Please don’t hesitate to contact us again if you need further assistance with anything else.
    ​​​​​​​

    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 ‘Add archive page only to sitemap’ is closed to new replies.