How to exclude content from the sitemap

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 inside the metabox in both Yoast SEO and Yoast SEO Premium, or exclude certain content types by customizing the sitemap index.

  1. Log in to your WordPress website.

    When you’re logged in, you will be in your ‘Dashboard’.

  2. Edit the post or page.

    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.

  3. Expand the ‘Advanced’ section and change the ‘Allow search engines to show this Post in search results?’ to ‘No’ for this post or page.

    Yoast SEO metabox with the allow search engines No or noindex selected

  4. Publish or update the post or page.

You or your developer can use the filter wpseo_exclude_from_sitemap_by_post_ids to bulk exclude post or pages from the Yoast SEO sitemap. The filter would be placed in your functions.php file. If you are not sure where that is please contact your theme developer. 

As a best practice we recommend a back-up be taken prior to editing theme files. 

The following is an example how you can use the filter:

add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function () {
  return array( 311, 322 );
} );