2

I want to exclude some specific post types from generating sitemaps in yoast seo plugin. Please provide suggestions to do this. Thanks in advance.

3 Answers 3

4

If you are using functions.php script to register custom post type, you should declare false to 'has_archive' => true,.

function custom_post_type() {

  $labels = array( ... );
  $args = array(

    // you have to set it to False.
    'has_archive' => false,

  );
  register_post_type( 'post_type', $args );

}
add_action( 'init', 'custom_post_type', 0 );
2

This question has been asked a long time ago, but the answer is kind of simple:

  • Go to SEO --> Search Appearance.
  • Select tab Contenttypes.
  • Scroll down, here you can display or hide custom post types and archives from the sitemap.xml file.

Hope that helps for someone.

2

If you need a filter solution:

add_filter( 'wpseo_sitemap_exclude_post_type', 'your_prefix_exclude_cpt_from_sitemap', 10, 2 );

function your_prefix_exclude_cpt_from_sitemap( $value, $post_type ) {
    $post_types_to_exclude = [
        'post_type_one',
        'post_type_two'
    ];
    
    if ( in_array($post_type, $post_types_to_exclude) ) {
        return true;
    }
}

You can use the "post_types_to_exclude" array to define multiple post types you want to exclude from the sitemap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.