Modifying the WordPress sitemap.xml output

Written by James McDonald

February 17, 2022

I use WordPress for customer websites with the Divi theme and layouts however WordPress is fundamentally a blogging platform so its sitemap.xml contains links to categories and users and you might not want to have those publicised and indexed by Google

The following snippet tells WordPress to skip a couple of the things it normally includes in the sitemap. In this case categories (taxonomies) and the users

Add this to your themes functions.php

add_filter( 'wp_sitemaps_add_provider', function ($provider, $name) {
  return ( in_array( $name, [ 'users', 'taxonomies' ])) ? false : $provider;
}, 10, 2);


Submit a Comment

Your email address will not be published.

You May Also Like…

List your VSCode Extensions

Ever wondered what extensions you have installed and want to keep a list? This actually is a good way to audit your...

array_merge vs the + operator

<?php $options = [ 'rootNode' => 'response' ]; // array_merge // the same key appearing later will overwrite echo...