How to Disable WordPress Core Sitemap: Code Methods and Plugin Solutions

WordPress automatically generates XML sitemaps since version 5.5, which can be helpful for SEO. However, there are times when you might want to disable this feature – perhaps you’re using a dedicated SEO plugin like Yoast or RankMath that creates more comprehensive sitemaps, or you simply don’t need the core sitemap functionality.

In this guide, we’ll explore several methods to disable WordPress core sitemaps using code snippets and a simple plugin approach.

The most straightforward way to disable WordPress core sitemaps is by adding a simple code snippet to your theme’s functions.php file.

Complete Sitemap Removal

// Disable WordPress core sitemaps completely
add_filter('wp_sitemaps_enabled', '__return_false');

Add this single line to your active theme’s functions.php file, and WordPress will stop generating all core sitemaps.

Selective Sitemap Removal

If you want more granular control, you can disable specific types of sitemaps:

// Disable specific sitemap providers
function disable_specific_sitemaps() {
    // Remove posts sitemap
    add_filter('wp_sitemaps_add_provider', function($provider, $name) {
        if ($name == 'posts') {
            return false;
        }
        return $provider;
    }, 10, 2);
    
    // Remove pages sitemap
    add_filter('wp_sitemaps_add_provider', function($provider, $name) {
        if ($name == 'pages') {
            return false;
        }
        return $provider;
    }, 10, 2);
    
    // Remove taxonomies sitemap
    add_filter('wp_sitemaps_add_provider', function($provider, $name) {
        if ($name == 'taxonomies') {
            return false;
        }
        return $provider;
    }, 10, 2);
    
    // Remove users sitemap
    add_filter('wp_sitemaps_add_provider', function($provider, $name) {
        if ($name == 'users') {
            return false;
        }
        return $provider;
    }, 10, 2);
}
add_action('init', 'disable_specific_sitemaps');

Method 2: Using wp-config.php

For a more permanent solution that won’t be affected by theme changes, you can add the disable code to your wp-config.php file:

// Add this line before "/* That's all, stop editing! */"
define('WP_DISABLE_SITEMAP', true);

// Then add this to your functions.php or in a plugin
if (defined('WP_DISABLE_SITEMAP') && WP_DISABLE_SITEMAP) {
    add_filter('wp_sitemaps_enabled', '__return_false');
}

Method 3: Custom Plugin Approach

Creating a simple plugin ensures the sitemap remains disabled regardless of theme changes. Create a new file called disable-wp-sitemap.php in your /wp-content/plugins/ directory:

<?php
/**
 * Plugin Name: Disable WordPress Core Sitemap
 * Description: Disables the core XML sitemap functionality introduced in WordPress 5.5
 * Version: 1.0
 * Author: Your Name
 */

// Prevent direct access
if ( ! defined('ABSPATH') ) {
    exit;
}

class DisableWPCoreSitemap {

    public function __construct() {
        add_action('init', array( $this, 'maybe_disable_sitemap' ));
        add_action('admin_menu', array( $this, 'add_admin_menu' ));
    }

    public function maybe_disable_sitemap() {
        $disable_sitemap = sanitize_text_field( get_option('disable_wp_sitemap', 'yes') );
        if ( 'yes' === $disable_sitemap ) {
            add_filter('wp_sitemaps_enabled', '__return_false');
        }
    }

    public function add_admin_menu() {
        add_options_page(
            'Disable WP Sitemap',       // Page title
            'Disable WP Sitemap',       // Menu title
            'manage_options',           // Capability
            'disable-wp-sitemap',       // Menu slug
            array( $this, 'admin_page' )
        );
    }

    public function admin_page() {
        // Only allow users with 'manage_options'.
        if ( ! current_user_can('manage_options') ) {
            wp_die( esc_html__('You do not have permission to modify this setting.', 'disable-wp-sitemap') );
        }

        // Check for form submission and nonce
        if ( isset($_POST['disable_wp_sitemap_nonce']) &&
             wp_verify_nonce( $_POST['disable_wp_sitemap_nonce'], 'disable_wp_sitemap_action' ) &&
             isset($_POST['submit'])
        ) {
            // Flag is either 'yes' or 'no'
            $new_value = isset($_POST['disable_sitemap']) && $_POST['disable_sitemap'] === 'yes'
                ? 'yes'
                : 'no';

            update_option( 'disable_wp_sitemap', $new_value );
            echo '<div class="notice notice-success"><p>'
                . esc_html__( 'Settings saved!', 'disable-wp-sitemap' )
                . '</p></div>';
        }

        $current_setting = sanitize_text_field( get_option('disable_wp_sitemap', 'yes') );
        ?>
        <div class="wrap">
            <h1><?php esc_html_e( 'Disable WordPress Core Sitemap', 'disable-wp-sitemap' ); ?></h1>
            <form method="post" action="">
                <?php
                // Output nonce for CSRF protection
                wp_nonce_field( 'disable_wp_sitemap_action', 'disable_wp_sitemap_nonce' );
                ?>
                <table class="form-table">
                    <tr>
                        <th scope="row"><?php esc_html_e( 'Disable Core Sitemap', 'disable-wp-sitemap' ); ?></th>
                        <td>
                            <label for="disable_sitemap_checkbox">
                                <input
                                    type="checkbox"
                                    id="disable_sitemap_checkbox"
                                    name="disable_sitemap"
                                    value="yes"
                                    <?php checked( $current_setting, 'yes' ); ?>
                                />
                                <?php esc_html_e( 'Disable WordPress core XML sitemap', 'disable-wp-sitemap' ); ?>
                            </label>
                            <p class="description">
                                <?php esc_html_e( 'Check to disable the core sitemap feature introduced in WordPress 5.5.', 'disable-wp-sitemap' ); ?>
                            </p>
                        </td>
                    </tr>
                </table>
                <?php submit_button(); ?>
            </form>

            <h2><?php esc_html_e( 'Current Sitemap Status', 'disable-wp-sitemap' ); ?></h2>
            <?php if ( 'yes' === $current_setting ) : ?>
                <p style="color: red;">
                    &#10005; <strong><?php esc_html_e( 'Core sitemap is currently disabled.', 'disable-wp-sitemap' ); ?></strong>
                </p>
            <?php else : ?>
                <p style="color: green;">
                    &#10003; <strong><?php esc_html_e( 'Core sitemap is currently enabled.', 'disable-wp-sitemap' ); ?></strong>
                </p>
                <p>
                    <a href="<?php echo esc_url( home_url('/wp-sitemap.xml') ); ?>" target="_blank">
                        <?php esc_html_e( 'View your sitemap', 'disable-wp-sitemap' ); ?>
                    </a>
                </p>
            <?php endif; ?>
        </div>
        <?php
    }
}

// Initialize the plugin
new DisableWPCoreSitemap();

https://gist.github.com/devuri/3e1059963d5716570e3e358e00411598

After creating this file, activate the plugin from your WordPress admin dashboard. You’ll find a new option under Settings > Disable WP Sitemap where you can toggle the sitemap on or off.

Method 4: Using .htaccess (Server-Level Block)

If you want to block access to the sitemap files at the server level, add this to your .htaccess file:

# Block access to WordPress core sitemaps
<Files "wp-sitemap*.xml">
    Order allow,deny
    Deny from all
</Files>

When Should You Disable Core Sitemaps?

Consider disabling WordPress core sitemaps when:

  • You’re using a comprehensive SEO plugin (Yoast, RankMath, etc.) that generates better sitemaps
  • You have a custom sitemap solution
  • Your site doesn’t need XML sitemaps for SEO purposes
  • You want to reduce server load from sitemap generation

Verification

To verify that the sitemap has been disabled, try accessing these URLs (replace yoursite.com with your domain):

  • https://yoursite.com/wp-sitemap.xml
  • https://yoursite.com/wp-sitemap-posts-post-1.xml
  • https://yoursite.com/wp-sitemap-taxonomies-category-1.xml

If the sitemaps are successfully disabled, these URLs should return a 404 error.

Important Considerations

Theme Independence: Using the plugin method or wp-config.php approach ensures your sitemap settings persist even when switching themes.

SEO Impact: Make sure you have alternative sitemaps in place (via SEO plugins) before disabling core sitemaps to maintain your SEO performance.

Caching: If you’re using caching plugins, clear your cache after implementing any of these methods.

Backup: Always backup your site before making changes to core files like functions.php or wp-config.php.

Conclusion

Disabling WordPress core sitemaps is straightforward with these methods. The functions.php approach is quickest for temporary changes, while the plugin method offers the most flexibility and permanence. Choose the method that best fits your workflow and technical comfort level.

Remember to monitor your site’s SEO performance after making changes and ensure you have proper sitemap alternatives in place if needed for your search engine optimization strategy.

Resources

WordPress Developer Handbook: XML Sitemaps

Official documentation detailing the built‑in sitemap functionality, available filters, and customization methods.
https://developer.wordpress.org/plugins/xml/custom-sitemaps/

WordPress Core Blog: “XML Sitemaps in WordPress 5.5”

Announcement and overview of the core sitemap feature introduced in WordPress 5.5, including design rationale and development background.
https://make.wordpress.org/core/2020/07/21/xml-sitemaps-in-wordpress-5-5/

Filter Reference: wp_sitemaps_enabled

Describes how the wp_sitemaps_enabled filter works, with usage examples for enabling or disabling all core sitemaps.
https://developer.wordpress.org/reference/hooks/wp_sitemaps_enabled/

Filter Reference: wp_sitemaps_add_provider

Explains the wp_sitemaps_add_provider hook, which allows selective removal or modification of individual sitemap providers (posts, pages, taxonomies, users).
https://developer.wordpress.org/reference/hooks/wp_sitemaps_add_provider/

Yoast SEO Documentation: XML Sitemaps

Details how Yoast SEO generates and manages sitemaps, and how it interacts with WordPress core sitemaps. Covers compatibility considerations and common troubleshooting.
https://yoast.com/help/xml-sitemaps-in-wordpress/

Rank Math Knowledge Base: Sitemap in WordPress

Step‑by‑step guide to Rank Math’s sitemap module, including how it automatically disables core sitemaps and how to configure custom settings.
https://rankmath.com/kb/sitemap-in-wordpress/

All in One SEO (AIOSEO) Docs: XML Sitemaps

Documentation on AIOSEO’s sitemap functionality, including details on automatically overriding the core sitemap and advanced options (e.g., priority, frequency).
https://aioseo.com/docs/xml-sitemap/

Apache HTTP Server Documentation: Using .htaccess Files

Comprehensive guide to .htaccess usage, syntax variations between Apache 2.2 and 2.4, and examples for blocking access to specific filenames (like wp-sitemap*.xml).
https://httpd.apache.org/docs/current/howto/htaccess.html

WordPress Support Forums: “Disable XML Sitemap” Thread

Community discussion where users share custom snippets, plugin recommendations, and troubleshooting tips for disabling or customizing core sitemaps.
https://wordpress.org/support/topic/disable-xml-sitemap/

WP Tavern: “WordPress 5.5 Introduces Core Sitemaps”

Independent news article covering the release of WordPress 5.5 sitemaps, including early testing notes and developer reactions.
https://wptavern.com/wordpress-5-5-introduces-core-sitemaps

Stack Overflow: Questions on Disabling WordPress Sitemaps

A compilation of highly‑voted Q&A posts demonstrating various code‑based approaches (including filters, actions, and plugin examples) for disabling core sitemaps.
https://stackoverflow.com/questions/tagged/wordpress+sitemap+disable

WP Codex: Editing wp-config.php Safely

Official guidance on how and where to add custom constants in wp-config.php without disrupting WordPress’s loading sequence.
https://codex.wordpress.org/Editing_wp-config.php

SiteGround Knowledge Base: Clearing WordPress Cache

Although SiteGround‑specific, this article covers general best practices for clearing various caching layers (plugin cache, object cache, server cache) after making code changes such as disabling sitemaps.
https://www.siteground.com/kb/clear-cache-wordpress/

DigWP: Advanced Uses of Filters and Hooks

Explains WordPress’s filter/hook system in detail, including best practices for writing anonymous functions and ensuring priority order when multiple filters modify sitemap behavior.
https://digwp.com/2011/09/wordpress-hooks-explained/