How to customize the sitemap index

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 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.

An impeccable site structure makes your content easy to find. Yoast SEO Premium contains several features that help you structure your site. By giving your website a structure boost, you get benefits for your SEO, your visitors, and search engines!

Available sitemaps

Content Types
Media and Images
Taxonomies
Archives
Other content

Related articles

Sitemap Feature
View Sitemaps
Limit the number of entries
Submit to Search Engines
Troubleshooting
Developer filters

Content types: Search appearance section

The sitemap index can be customized under SEO > Search Appearance. Posts, pages, and other custom post types can be customized 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. Log in to your WordPress website. When you』re logged in, you will be in your 『Dashboard』. Click on 『SEO』. On the left-hand side, you will see a menu. In that menu, click on 『SEO』. Click on 『Search Appearance』. The 『SEO』 settings will expand providing you additional options. Click on 『Search Appearance』. Click on the appropriate tab and toggle Show [type] in search results? to add or remove sitemaps. Yes: [type] will be set to index and a sitemap will be created.No: [type] will be set to noindex and a sitemap will not be created. 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, the post type can either be made public or manually excluded using a developer filter.

Content types: Removing it individually 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

Categories, tags, and other taxonomies can be customized 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

Our Video SEO plugin sitemap can be customized under Admin > SEO > Video SEO.

News sitemap

Our News SEO plugin sitemap can be customized under Admin > 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. If you are not familiar with implementing code in WordPress, we highly recommend checking out Code Poet as they have a great list of available freelance WordPress developers. You may also wish to review a Yoast Partner.

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

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注