SEO PHP Beginner

Turn Off the Built-In WordPress Sitemap

Disable /wp-sitemap.xml when another plugin provides your sitemap, so search engines only see one.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 1 lines
add_filter( 'wp_sitemaps_enabled', '__return_false' );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Since version 5.5, WordPress creates a sitemap at /wp-sitemap.xml. If a plugin creates a different sitemap and doesn’t switch the core one off, search engines find two. This line turns the core sitemap off.

How it works

WordPress checks wp_sitemaps_enabled before serving any sitemap URL. Returning false makes them all return 404 and removes the Sitemap line from the virtual robots.txt.

Things to watch

  • Most SEO plugins already disable the core sitemap. Only add this if you can still open /wp-sitemap.xml alongside your plugin’s sitemap.
  • If you turn off core sitemaps without another sitemap, submit nothing in Search Console rather than an address that 404s.

How to test it

Visit yoursite.com/wp-sitemap.xml. It should return your 404 page.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only