Exclude Specific Posts and Pages From the Yoast Sitemap
Keeps the posts and pages you list out of the Yoast SEO XML sitemaps while leaving them indexable.
Opens WPIDE on
Code
// IDs to leave out of the sitemap.
$wpide_sitemap_exclude = array( 12, 34, 56 );
add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function ( $ids ) use ( $wpide_sitemap_exclude ) {
return array_unique( array_merge( (array) $ids, array_map( 'intval', $wpide_sitemap_exclude ) ) );
} );
Notes
Yoast caches sitemaps; save any post afterwards to refresh them.
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.