How to remove users list from sitemap in WordPress (the right way)

As you might know in WordPress, under https://yourdomain/sitemap.xml all users are exported through the dedicated xml url, list like so:

URL
https://yourdomain/wp-sitemap-posts-post-1.xml
https://yourdomain/wp-sitemap-posts-page-1.xml
https://yourdomain/wp-sitemap-taxonomies-category-1.xml
https://yourdomain/wp-sitemap-taxonomies-post_tag-1.xml
https://yourdomain/wp-sitemap-users-1.xml

Actually, it’s not a good idea to make your users lists available publicly.

Fortunately, there are multiple ways to solve this. One way is, in wp-includes\sitemaps\class-wp-sitemaps-registry.php file find the method public function add_provider(..) and add the next code just right after the method’s open parenthesis:

public function add_provider( $name, WP_Sitemaps_Provider $provider ) {
    if ($name == 'users') {
        return false;
    }
}

Warning note:

Don’t forget to repeat this change when updating the WordPress, as the automatic update will overwrites your class-wp-sitemaps-registry.php file and changes will be lost.

Actually, the above solution is what I found surfing on over the internet, but when I deep dive into to source code, found even easier way: In wp-includes\sitemaps\class-wp-sitemaps.php under register_sitemaps() method just comment out the users provider like so:

public function register_sitemaps() {
    $providers = array(
        'posts'      => new WP_Sitemaps_Posts(),
        'taxonomies' => new WP_Sitemaps_Taxonomies(),
        // 'users'      => new WP_Sitemaps_Users(),
    );
}

Leave a Reply