Rank Math lets you choose which post types go into the XML sitemap with the Include in Sitemap toggle under Rank Math SEO > Sitemap Settings > Post Types.
To exclude a post type from the Rank Math sitemap in code instead, use the rank_math/sitemap/exclude_post_type filter.
Code is the better choice when the decision depends on a condition, when a plugin or theme you ship registers the post type, or when you don’t want the setting switched back on from the dashboard.
To move the sitemap itself to a different address, see change the sitemap URL base in Rank Math.
The Code
Add this to your child theme’s functions.php file or to a small custom plugin:
/**
* Filter decision if post type is excluded from the XML sitemap.
*
* @param bool $exclude Default false.
* @param string $type Post type name.
*/
add_filter( 'rank_math/sitemap/exclude_post_type', function( $exclude, $type ){
if ( 'snippet' === $type ) {
return true;
}
return $exclude;
}, 10, 2 );
How It Works
Rank Math runs this filter for every post type that has Include in Sitemap turned on. It passes two arguments: $exclude (default false) and $type, the post type name.
Return true and that post type’s sitemap file (for example snippet-sitemap.xml) is no longer generated or listed in the sitemap index. For every other type, return $exclude unchanged so you don’t override other code that uses the same filter.
Replace 'snippet' with your post type’s name. That is the key passed to register_post_type(), not the label shown in the admin menu.
The filter can only remove post types. It can’t bring back a post type whose Include in Sitemap setting is off, because Rank Math checks that setting before it runs the filter.
To exclude several post types at once, compare against an array:
add_filter( 'rank_math/sitemap/exclude_post_type', function( $exclude, $type ) {
$excluded = array( 'snippet', 'portfolio', 'testimonial' );
return in_array( $type, $excluded, true ) ? true : $exclude;
}, 10, 2 );
Exclude a Single Page Instead
If you only want to remove one page or post from the sitemap, you don’t need to exclude the whole post type. Rank Math gives you three ways to do it:
- Set the page’s Robots Meta to No Index in its Rank Math settings. Rank Math leaves noindex content out of the sitemap by default.
- Add the ID to Sitemap Settings > General > Exclude Posts (comma-separated). It’s an advanced option, so switch Rank Math to Advanced Mode if you don’t see the field.
- Use the
rank_math/sitemap/entry filter and return false for that URL.
Here is the code version, which removes posts 42 and 108 from whatever sitemap they belong to:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ) {
if ( 'post' === $type && in_array( (int) $object->ID, array( 42, 108 ), true ) ) {
return false;
}
return $url;
}, 10, 3 );
$type is post for all post types (pages included), term for taxonomy terms and user for authors. Cast the ID to an integer: Rank Math reads these rows straight from the database, so the ID arrives as a string and a strict comparison would never match.
Both filters are listed in the Rank Math filters and hooks reference.
Check That It Worked
Rank Math caches generated sitemaps, so the old version can still show after you add the filter. If you have WP-CLI, this command clears the cache and rebuilds the sitemap:
wp rankmath sitemap generate
Then open your sitemap index and confirm the post type’s sitemap is gone. If a page cache or CDN sits in front of the site, purge it too, or you may be looking at a stored copy.
For the bigger picture on what belongs in a sitemap and how to submit it, read how to create and submit a sitemap for WordPress sites.
FAQs
Common questions about excluding content from the Rank Math sitemap:
Is there a rank_math/sitemap/post_types filter?
No. Rank Math has no filter by that name. Use rank_math/sitemap/exclude_post_type to remove a post type, or the Include in Sitemap toggle under Sitemap Settings > Post Types.
Does excluding a post type from the sitemap stop Google from indexing it?
No. The posts stay indexable, and Google can still find them through links. If you want them out of search results, set the post type to noindex under Rank Math SEO > Titles & Meta.
How do I exclude a taxonomy from the Rank Math sitemap?
Use rank_math/sitemap/exclude_taxonomy. It works the same way: it receives $exclude and the taxonomy name, and returning true removes that taxonomy's sitemap.
I added the filter but the post type is still in the sitemap. Why?
Usually it's the sitemap cache or a page cache. Run wp rankmath sitemap generate, purge your caching plugin or CDN, and check that the name in the code matches the registered post type key exactly.