A feature plugin to integrate basic XML Sitemaps in WordPress Core
As originally proposed in June 2019, this feature plugin seeks to integrate basic XML Sitemaps functionality in WordPress Core.
A short explanation of how this plugin works can be found on this make/core blog post.
Interested in contributing to this plugin? Feel free to join us in the #core-sitemaps Slack channel.
- Local Setup: Local Setup Documentation Section.
- Contributing: Contributing Documentation Section
- Testing: Testing Documentation Section.
You can use remove_action( 'init', 'core_sitemaps_get_server' );
to disable initialization of any sitemap functionality.
You can use the core_sitemaps_register_providers
filter to disable sitemap generation for posts, users, or taxonomies.
You can use the core_sitemaps_post_types
filter to disable sitemap generation for posts of a certain type.
By default, only public posts will be represented in the sitemap.
Similarly, the core_sitemaps_taxonomies
filter can be used to disable sitemap generation for certain taxonomies.
Example: Disabling sitemaps for the "page" post type
add_filter(
'core_sitemaps_post_types',
function( $post_types ) {
unset( $post_types['page'] );
return $post_types;
}
);
Example: Disabling sitemaps for the "post_tag" taxonomy
add_filter(
'core_sitemaps_taxonomies',
function( $taxonomies ) {
unset( $taxonomies['post_tag'] );
return $taxonomies;
}
);
The core_sitemaps_taxonomies_url_list
, core_sitemaps_taxonomies_url_list
, and core_sitemaps_users_url_list
filters allow you to add or remove URLs as needed.
Example: Ensuring the page with ID 42 is not included
add_filter(
'core_sitemaps_posts_url_list',
function( $urls, $type ) {
if ( 'page' === $type ) {
$post_to_remove = array( 'loc' => get_permalink( 42 ) );
$key = array_search( $post_to_remove, $urls, true );
if ( false !== $key ) {
array_splice( $urls, $key, 1 );
}
}
return $urls;
},
10,
2
);
Example: Ensuring the category with ID 1 is not included
add_filter(
'core_sitemaps_taxonomies_url_list',
function( $urls, $type ) {
if ( 'category' === $type ) {
$term_to_remove = array( 'loc' => get_term_link( 1 ) );
$key = array_search( $term_to_remove, $urls, true );
if ( false !== $key ) {
array_splice( $urls, $key, 1 );
}
}
return $urls;
},
10,
2
);
Example: Ensuring the user with ID 1 is not included
add_filter(
'core_sitemaps_users_url_list',
function( $urls ) {
$user_to_remove = array( 'loc' => get_author_posts_url( 1 ) );
$key = array_search( $user_to_remove, $urls, true );
if ( false !== $key ) {
array_splice( $urls, $key, 1 );
}
return $urls;
}
);
Use the core_sitemaps_max_urls
filter to adjust the maximum number of URLs included in a sitemap. The default value is 2000 URLs.
A variety of filters exists to allow you adjust the styling:
core_sitemaps_stylesheet_url
- Filter the URL for the sitemap stylesheet.core_sitemaps_stylesheet_index_url
- Filter the URL for the sitemap index stylesheet.core_sitemaps_stylesheet_content
- Filter the content of the sitemap stylesheet.core_sitemaps_index_stylesheet_content
- Filter the content of the sitemap index stylesheet.core_sitemaps_stylesheet_css
- Filter the CSS only for the sitemap stylesheet.
No. Those are optional fields in the sitemaps protocol and not typically consumed by search engines. Developers can still add those fields if they really want too.
See CHANGELOG.md.