Keep content types you don't want indexed, such as tags or a private custom post type, out of WordPress's XML sitemap.
// Post types to leave out of /wp-sitemap.xml.
add_filter( 'wp_sitemaps_post_types', function ( array $post_types ): array {
unset( $post_types['portfolio'] );
return $post_types;
} );
// Taxonomies to leave out.
add_filter( 'wp_sitemaps_taxonomies', function ( array $taxonomies ): array {
unset( $taxonomies['post_tag'] );
return $taxonomies;
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
WordPress’s sitemap lists every public post type and taxonomy. If tag pages are thin or a custom post type isn’t meant for search, leaving them out keeps search engines focused on the pages that matter.
wp_sitemaps_post_types and wp_sitemaps_taxonomies return the post types and taxonomies included in the sitemap, keyed by name. Removing a key takes its sitemap out of the index.
post_tag rather than “Tags”. You can see them in the URL when editing.Open yoursite.com/wp-sitemap.xml. The removed types should no longer be listed.