How to exclude pages from a WordPress sitemap

& why you might want to

By Chris · 2 July 2025

Back in August 2020, Version 5.5 of WordPress introduced automatic XML sitemaps to help search engines better understand your website structure.

Here’s the original announcement from the 5.5 documentation:

Now, by default, WordPress 5.5 includes an XML sitemap that helps search engines discover your most important pages from the very minute you go live.

So more people will find your site sooner, giving you more time to engage, retain and convert them to scribers, customers or whatever fits your definition of success.

Before this, website owners, developers, SEO agencies and so on had to use plugins like Yoast SEO, XML Sitemap Generator for Google, or similar. Plugins are fine here and there, but as more and more are required to achieve and maintain bespoke functionality, they can lead to bloated and clunky backends that impact frontend performance.

So the change made life a lot easier for website owners and third parties like SEO agencies.

How to remove pages from the WordPress XML sitemap

That said, all pages being included automatically isn’t always desireable. There are a bunch of reasons you might want to include one/some page(s), or even full taxonomies:

  • Communicate your priorities: the goal of a sitemap is to signal intent and tell search engines the content you want them to index, so you can leave out thin pages, pages with similar content to other pages, and so on
  • Hide placeholder or testing pages: sometimes having ‘coming soon’ pages can be helpful for visitors, or you might have pages live for internal review that aren’t ready to be public-facing yet
  • Hide private or restricted pages: if you have client dashboards, user areas, subscriber-only content or similar, it can be better to leave this out of the index
  • Consistency between sitemap and noindex pages: if you’ve tagged pages with noindex directive, it makes sense to ensure consistency with the sitemap – otherwise you’re sending mixed signals to Google
  • Auto-generated content: if you use custom post types and each one has an archive, or you have tons of blog content, archive pages can quickly cause index bloat

And here’s how to do it. In the spirit of minimising backend bloat we’ll just cover plugin-free options here.

Removing pages via functions.php

Head to Appearance – Theme file editor – functions.php from your WordPress backend (note you need admin privileges), then add this code snippet:

function exclude_pages_from_sitemap($post_ids, $post_type) {
if ($post_type === 'page') {
$post_ids[] = 42; 
$post_ids[] = 99;
}
return $post_ids;
}
add_filter('wp_sitemaps_posts_exclude', 'exclude_pages_from_sitemap', 10, 2);

Replace the placeholder ids (42, 99) with the IDs of the pages you want to exclude. To find these, head to Pages then hover over the name of each desired page. In the bottom left of the screen you’ll see something like:

https://plaudit.agency/wp-admin/post.php?post=311&action=edit

The number after post= is the ID

Removing post types via functions.php

To remove an entire post type, head to functions.php and add this code snippet:

function remove_post_type_from_sitemap($args, $post_type) {
if ($post_type === 'portfolio') {
$args['exclude_from_search'] = true;
}
return $args;
}
add_filter('wp_sitemaps_post_type_args', 'remove_post_type_from_sitemap', 10, 2);

The post_type name is case sensitive, so make sure it matches exactly with the name in the function where you registered the post type.

Use cases for removing pages from WordPress XML sitemaps

It’s important to keep in mind that removing pages from the WordPress sitemap doesn’t mean they won’t be indexed at all. What you’re doing is letting Google know you don’t think they should be indexed.

Here are some use cases for removing pages from the sitemaps that might end up being indexed:

  • Useful content that’s low priority for SEO: stuff like thank you pages, password reset pages, resource pages not meant for search
  • Accessible but not strategically important pages: old blog posts, out of date press releases, etc
  • You have tons of pages and want to make crawls more efficient: on very big sites you can use the sitemap to curate the pages Google will crawl, reducing the likelihood of it choosing the wrong content
  • Keeping your sitemap within Google’s recommended limits: if it’s more than 50k URLs or 50mb file size, removing pages can help you get it down

Other steps to take if you want to ensure content isn’t indexed

If you want to force Google and other search engines not to index your content at all, there are additional actions you can take:

  • Add a noindex tab
  • Block with robots.txt
  • Add a password or otherwise restrict access
  • Remove internal links to the pages
  • Request removal on Google Search Console

Need help refining your WordPress sitemap?

If you’re dealing with index bloat and crawl inefficiencies or just want to tidy up the signals you’re sending to search engines, we can help. Get in touch for a technical SEO audit or a quick chat.

Table of Contents

Featured Posts

Search history

SEO has changed so much, but it also hasn’t changed at all

Read more