How to remove author sitemaps from WordPress

In the WordPress 5.5 release they have added the ability to generate a XML sitemap. XML sitemap are great because it tell search engines such as Google and Bing what pages to crawl. One of the sitemap which the WordPress core creates is a user sitemap. On a WordPress site I work on we didn’t want to use this feature, so I’m going to go through the process how to disable the sitemap.

How to remove author sitemap from WordPress

The way in which I can do this is a placing the following code below into your functions.php

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

add_filter('wp_sitemaps_add_provider', 'remove_author_category_pages_from_sitemap', 10, 2);

What the code does is creates a function called remove_author_category_pages_from_sitemap with two arguments $provider and $name. If the name of the sitemap is users the function return false. Otherwise if it’s not a user sitemap it will build the xml file as usual.

We then create a add_filter hook on wp_sitemaps_add_provider then add the function we just created. Finally we give the sitemap a priority of 10 and tell the hook to accept 2 arguments.

As you can see from the code above it’s very easy to remove user sitemaps from your WordPress site.

Leave a Reply

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