I have been using my WordPress site to create various types of content, I obviously submit my sitemaps to Google for getting my site indexed. But there is some content which I don’t want on Google, and therefore don’t want it in Sitemaps too.

I used to use a plugin to implement it, but now we have got overlapping functionalities, as WordPress supports sitemaps now.

So How can I either completely remove the WordPress sitemap, so that I just use the Plugin, and Google Search Console cant read my wp-sitemap.xml, OR selectively remove some posts from WordPress Sitemap, so that I can Customize Sitemap to my taste, and then remove the Sitemap Plugin

1 Answer
1

Disabling the sitemap is easy, just add this line to your functions.php:

add_filter( 'wp_sitemaps_enabled', '__return_false' );

Removing specific posts goes like this:

add_filter(
    'wp_sitemaps_posts_query_args',
    function( $args, $post_type ) {
        if ( 'post' !== $post_type ) {
            return $args;
        }
 
        $args['post__not_in'] = isset( $args['post__not_in'] ) ? $args['post__not_in'] : array();
        $args['post__not_in'][] = 123; // 123 is the ID of the post to exclude.
        return $args;
    },
    10,
    2
);

There a quite a lot of ways to customize the sitemap if you would rather use the WP native way than a plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *