Exclude Content Types From the XML Sitemap
Removes chosen post types and taxonomies (tags by default) and the users list from the built-in wp-sitemap.xml.
Opens WPIDE on
Code
add_filter( 'wp_sitemaps_post_types', function ( $post_types ) {
// Post type names to leave out, for example 'page'.
foreach ( array() as $name ) {
unset( $post_types[ $name ] );
}
return $post_types;
} );
add_filter( 'wp_sitemaps_taxonomies', function ( $taxonomies ) {
unset( $taxonomies['post_tag'], $taxonomies['post_format'] );
return $taxonomies;
} );
add_filter( 'wp_sitemaps_add_provider', function ( $provider, $name ) {
return 'users' === $name ? false : $provider;
}, 10, 2 );
Notes
Add post type names to the empty array to exclude them.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.