# 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.

- Type: PHP
- Runs: Frontend only
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: yoast, sitemap, exclude
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/yoast-sitemap-exclude-ids/

## Code

```php
// 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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Exclude Specific Posts and Pages From the Yoast Sitemap" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
