How to customize the sitemap index

The Yoast SEO plugin generates a sitemap of your site. It is a crucial feature of the plugin, and it helps search engines find and crawl your pages. The sitemap index includes links to a variety of sub-sitemaps for posts, pages, authors, categories, tags, and other taxonomies. In Yoast SEO, you can customize the XML sitemap index, and choose what you show in it. If you are not sure what needs to go in the sitemap, read this article first.


Warning: Undefined array key “className” in /home/staging-yoast/staging-platform.yoast.com/versions/05aa62c2ec01538957086672ffa4a059780fd784/web/app/themes/yoast-theme/html_includes/blocks/landing-page/block-landing-page-list.php on line 21

You can improve the way search engines crawl your site with the Crawl optimization settings in Yoast SEO Premium! They allow you to remove unnecessary URLs, so search engines can crawl your site more efficiently!

How to customize the sitemap index

You can customize the sitemap index in the “Content types”, “Categories & tags”, and “Advanced” settings of Yoast SEO. You’ll find these settings under Yoast SEO > Settings.

You can customize posts, pages, and other custom post types under the “Content types” tab. Removing a post type from the search results will also remove them from the sitemap. Showing them in the search results will show them in the sitemap. Add or remove items as needed.

  1. Log in to your WordPress website.

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

  2. Click on “Yoast SEO”.

    On the left-hand side, you will see a menu. In that menu, click on “Yoast SEO”.
    Screenshot of the "Yoast SEO" menu item.

  3. Click on “Settings”.

    The “Yoast SEO” settings will expand, providing you with additional options. Click on “Settings”.
    Screenshot of the settings menu item in Yoast SEO

  4. Click on the appropriate menu item and enable or disable the toggle Show [type] in search results? to add or remove sitemaps.

    Enabled: [type] will be set to index and a sitemap will be created.
    Disabled: [type] will be set to noindex and a sitemap will not be created.
    Screenshot of the "Show categories in search results" toggle in the Yoast SEO settings

  5. Click “Save Changes”.

Content types: Not publicly added

Some content types are not added publicly and thus do not appear for exclusion. When this occurs, you can either make the post type public or manually exclude it using a developer filter.

Remove individual URLs from sitemap

You can also remove individual post types from the sitemap by marking them with a noindex tag. Use this guide if you are not sure how to do that: How do I noindex URLs?

Media and images

When you upload an image, WordPress automatically creates a post of the type “attachment” in the database, and the corresponding URL for that. It calls this the “media” post type. Learn more here.

Taxonomies

You can customize categories, tags, and other taxonomies under the ‘Taxonomies’ tab. Some taxonomies are not added publicly and thus do not appear for exclusion. When this occurs, the taxonomy can either be made public or manually excluded using a developer filter.

Archives: Author sitemap

Our plugin creates a sitemap that lists the author pages. Learn more about customizing the author sitemap for single author websites or multiple author websites.

Other sitemaps

Video sitemap

You can customize our Video SEO plugin sitemap under Yoast SEO > Video SEO.

News sitemap

You can customize our News SEO plugin sitemap under Yoast SEO > News SEO.

Local sitemap

Our Local SEO plugin sitemap is generated based on the location data entered into the plugin.

Non-Yoast plugin sitemaps

You can add non-Yoast sitemaps to the index. Please read this article for more information.

Below are a few examples using the developer filters in your functions.php file to customize the sitemaps.

Content types

Filter: wpseo_sitemap_exclude_post_type

/* Exclude One Content Type From Yoast SEO Sitemap */
function sitemap_exclude_post_type( $value, $post_type ) {
if ( $post_type == 'post_type_slug' ) return true;
}
add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );
/* Exclude Multiple Content Types From Yoast SEO Sitemap */
add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );
function sitemap_exclude_post_type( $value, $post_type ) {
$post_type_to_exclude = array('post_type_slug1','post_type_slug2', 'post_type_slug3');
if( in_array( $post_type, $post_type_to_exclude ) ) return true;
}

Taxonomies

Filter: wpseo_sitemap_exclude_taxonomy

/* Exclude One Taxonomy From Yoast SEO Sitemap */
function sitemap_exclude_taxonomy( $value, $taxonomy ) {
if ( $taxonomy == 'taxonomy_slug' ) return true;
}
add_filter( 'wpseo_sitemap_exclude_taxonomy', 'sitemap_exclude_taxonomy', 10, 2 );
/* Exclude Multiple Taxonomies From Yoast SEO Sitemap */
add_filter( 'wpseo_sitemap_exclude_taxonomy', 'sitemap_exclude_taxonomy', 10, 2 );
function sitemap_exclude_taxonomy( $value, $taxonomy ) {
$taxonomy_to_exclude = array('taxonomy_slug1','taxonomy_slug2', 'taxonomy_slug3');
if( in_array( $taxonomy, $taxonomy_to_exclude ) ) return true;
}

Authors

Filter: wpseo_sitemap_exclude_author

Entries per sitemap

You can change the number of entries per sitemap by using the filter below. The default number is 1000. Please refer to this code snippet as an example.

wpseo_sitemap_entries_per_page

Exclude posts and pages

To exclude posts and pages from the sitemap follow the instructions here

Exclude a term from the sitemap

Use the filter below:

wpseo_exclude_from_sitemap_by_term_ids

Add an external sitemap

To add an external sitemap follow the instructions here

Work with dynamic URLs

Please refer to this GitHub comment for how you may best integrate dynamic URLs.

Change post URLs for the sitemap

You can use this filter to change post URLs for the sitemap:

wpseo_xml_sitemap_post_url

Did this article answer your question?

Thanks for your feedback!

Get free SEO tips!