# Exclude Specific Posts From the Rank Math Sitemap

> Leaves the posts and pages you list out of Rank Math's XML sitemaps without changing their robots settings.

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

## Code

```php
// IDs to leave out.
$wpide_rm_sitemap_exclude = array( 12, 34 );

add_filter( 'rank_math/sitemap/entry', function ( $url, $type, $object ) use ( $wpide_rm_sitemap_exclude ) {
    if ( 'post' === $type && $object instanceof WP_Post && in_array( (int) $object->ID, array_map( 'intval', $wpide_rm_sitemap_exclude ), true ) ) {
        return false;
    }

    return $url;
}, 10, 3 );
```

## Notes

Rank Math caches sitemaps; clear the cache or update a post to see the change.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Exclude Specific Posts From the Rank Math 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/
