duane blake

Published on September 23, 2020 | Posted in Wordpress

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.

8 comments

  1. Mister Dif says:

    This works beautifully. Can’t understand why this was implemented since it creates less secure websites by giving away the admin login. Thanks so much for posting this.

  2. Mister Dif says:

    Works perfectly. Love not having to add the Yoast plugin to do this. Thank you for this!

  3. Noo says:

    thanks dude i was looking for this.

  4. Marcin says:

    Thank you, you’re brilliant, I didn’t know how to deal with it and I didn’t want to install seo plugins. Thank you, my friend

  5. JVC says:

    Thank you! This code saves the hassle of installing plugins and gets the job done.

  6. Michael says:

    You’re not limited to ‘users’ in this solution either. Here are the other possible $name values.

    posts
    taxonomies
    users
    posts

    If you wanted to remove the post categories, you could include

    if (‘users’ === $name || ‘taxonomies’ === $name) {

  7. JooLeeK says:

    Thankyou 😉

  8. Thanks so much. This really helped

Leave a comment

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