How to exclude a page from the WordPress XML sitemap

A page usually comes out of the sitemap because it should not be in search results, and then the fix is noindex: in Hydrogen SEO, switch on No Index in the page's SEO Settings sheet and it leaves the sitemap automatically. To unlist a page but keep it indexable, use a filter.

A sitemap is a list of URLs you would like indexed. Leaving a page out does not hide it. Google can still find it through links and index it. So decide first which of the two outcomes you want.

Step by step

1. Decide what you are trying to achieve

  • Keep the page out of Google: noindex it. Sitemap removal follows.
  • Stop listing it but allow indexing: exclude it by filter. This is rare, and mostly cosmetic.
  • Remove a whole content type: switch the type off on the Sitemap screen instead of excluding entries one by one.

Thank-you pages, internal landing pages for ads and account pages belong in the first group.

2. Noindex the page

  1. Open the page in the editor and open the SEO Settings sheet (⌘E or Ctrl+E).
  2. Open Robots Meta and switch on No Index.
  3. Update the page.

From the Pages list, Quick Edit → Indexing → No index does the same without opening the editor. Hydrogen SEO leaves noindexed posts out of the sitemap, along with password-protected posts, drafts and private posts, which are never listed.

3. Confirm it is gone

Open Hydrogen SEO → Sitemap, click View Sitemap, open the sitemap for the post type (sitemap-page.xml for pages) and search for the URL. The plugin clears its sitemap cache when content changes, so the entry should already be missing. If it is still there, a page cache or CDN in front of the site is serving an older copy of the XML. Purge it.

4. Exclude without noindex, using the plugin's filter

For the rare case where a page should stay indexable but unlisted, return true for its ID:

php
add_filter( 'hydrogen_seo_sitemap_exclude_item', function ( $excluded, $object_id, $type ) {
    if ( 'post' === $type && in_array( (int) $object_id, array( 42, 87 ), true ) ) {
        return true;
    }
    return $excluded;
}, 10, 3 );

$type is post for posts, pages and custom post types. Find a page's ID in the address bar of its edit screen: post=42.

5. Do the same with the core sitemap

On a site using WordPress's built-in sitemap at /wp-sitemap.xml, exclude by ID through the query arguments:

php
add_filter( 'wp_sitemaps_posts_query_args', function ( $args, $post_type ) {
    if ( 'page' === $post_type ) {
        $args['post__not_in'] = array( 42, 87 );
    }
    return $args;
}, 10, 2 );

Core has no per-post noindex, so there the filter is the only route. This filter has no effect while Hydrogen SEO is active, because the plugin switches the core sitemap off and redirects /wp-sitemap.xml to its own /sitemap.xml.

6. Remove a whole post type or taxonomy

On Hydrogen SEO → Sitemap, the Post Types and Taxonomies cards have a switch per type. Turn one off and click Save Changes in the top bar. Unlike most screens in the plugin, this one does not save as you click. Saving refreshes the sitemap cache, and that type's sitemap leaves the index at once.

7. Tell Search Console only if it matters

You do not need to resubmit the sitemap. Google re-reads it on its own schedule. If you noindexed the page and want it out of results quickly, inspect the URL in Search Console and click Request indexing so the tag is seen sooner.

What exclusion does not do

Removing a URL from the sitemap does not deindex it, does not stop crawling and does not make it private. If the page is linked from your menu or from other sites, search engines keep finding it. For removal from results use noindex. For privacy use a password or a login. A sitemap entry is one hint about which URLs matter, and its absence is a weak signal at most.

Pages that are left out already

Before adding code, check that the page is in the sitemap at all. Hydrogen SEO leaves out noindexed content, password-protected posts and anything unpublished. Terms with no posts are left out while Noindex Empty Archives is on. Posts of a type set to Noindex on the Robots screen are left out together, and that type shows a NoIndex badge on the Sitemap screen.

Common questions

How do I remove a page from my WordPress sitemap?

Set the page to noindex in its SEO settings and it drops out automatically. To keep it indexable but unlisted, exclude its ID with the sitemap filter.

Does removing a page from the sitemap remove it from Google?

No. Google can still crawl and index it through links. Use a noindex tag to remove a page from results.

Should noindexed pages be in the sitemap?

No. Listing a URL while telling search engines not to index it sends conflicting signals, and Search Console reports it against the submitted sitemap.