Exclude Post Types From the Yoast Sitemap
Removes whole post types, such as landing pages or a plugin's internal post type, from the Yoast SEO sitemap index.
Opens WPIDE on
Code
// Post type names to leave out of the sitemap.
$wpide_sitemap_skip_types = array( 'landing', 'attachment' );
add_filter( 'wpseo_sitemap_exclude_post_type', function ( $excluded, $post_type ) use ( $wpide_sitemap_skip_types ) {
return in_array( $post_type, $wpide_sitemap_skip_types, true ) ? true : $excluded;
}, 10, 2 );
Notes
To also hide them from search, set them to noindex in Yoast's Content types settings.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.