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 about XML sitemaps first.

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 in the Yoast SEO menu under 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. Go to 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


    Screenshot of the settings menu item in Yoast SEO

  4. Click on the sitemap item and enable or disable the toggle Show [type] in search results? 

    If the item is enabled, it’ll be purple and show a checkmark. If the item is disabled, it’ll show a gray x-mark.
    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 our How do I noindex URLs guide for more information.

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. Learn more about media post types in our article on images in the XML sitemap.

Taxonomies

You can customize categories, tags, and other taxonomies under the Categories & tags 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 Video SEO in the Yoast SEO menu.

News sitemap

You can customize our News SEO plugin sitemap under News SEO in the Yoast SEO menu.

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 our article on adding external sitemaps for more information.

Below are a few examples of 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 our 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!

Related articles

Get free SEO tips!