Since WordPress now creates sitemaps automatically since version 5.5, excluding a particular page is not widely known.
The code below will exclude a page from the wp-sitemap.xml
// Remove specific pages
function gt_disable_sitemap_specific_page($args, $post_type) {
if ('page' !== $post_type) return $args;
$args['post__not_in'] = isset($args['post__not_in']) ? $args['post__not_in'] : array();
$args['post__not_in'][] = 221; //locations
$args['post__not_in'][] = 261; //blog
return $args;
}
add_filter('wp_sitemaps_posts_query_args', 'gt_disable_sitemap_specific_page', 10, 2);
// Remove custom specific types
function gt_disable_sitemap_post_types($post_types) {
unset($post_types['elementor_library']);
return $post_types;
}
add_filter('wp_sitemaps_post_types', 'gt_disable_sitemap_post_types');
// Remove Users
add_filter( 'wp_sitemaps_add_provider', function ($provider, $name) {
return ( $name == 'users' ) ? false : $provider;
}, 10, 2);
// Remove Taxonomies
function remove_tax_from_sitemap( $taxonomies ) {
unset( $taxonomies['category'] );
//or empty the entire lot (for example if using woocommerce)
//$taxonomies=[];
return $taxonomies;
}
add_filter( 'wp_sitemaps_taxonomies', 'remove_tax_from_sitemap' );











