How to exclude posts / pages from the sitemap

Last update: 13 July, 2018

Posts and pages can be assigned to multiple taxonomies and thus may unexpectedly show up in your sitemap when you thought it would be hidden. You can exclude individual posts or pages from the sitemap using the Yoast SEO metabox.

Exclude post or page from sitemaps with the Yoast metabox

  • Log in to your WordPress website. When you're logged in, you will be in your 'Dashboard'. On the left-hand side, you will see a menu. In that menu, navigate to the post or page (or other custom post type) you'd like to exclude.
  • Scroll to the Yoast SEO metabox and click on the advanced settings.
  • Change the  'Allow search engines to show this Post in search results?' to 'No' for this post or page. 
  • Publish or update the post or page

Exclude post or page from sitemaps with a filter

You can use the filter wpseo_exclude_from_sitemap_by_post_ids to exclude post or pages from the sitemap. The following is an example how you can use the filter:

<br />
add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function () {
  return array( 311, 322 );
} );
?><br />

Was this article helpful? ·