#58379 closed defect (bug) (invalid)
Can't disable the default wordpress xml sitemap
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Sitemaps | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
Hi,
I created a custom sitemap for my website and I Want to disable the default wordpress (v6.1.1) sitemap (/wp-sitemap.xml). I added this code to functions.php add_filter( 'wp_sitemaps_enabled', '__return_false' );
but nothing happened. The sitemap still accessible at /wp-sitemap.xml
Change History (10)
#2
@
21 months ago
- Keywords reporter-feedback added
- Severity changed from critical to normal
- Version 6.1.1 deleted
#4
follow-up:
↓ 7
@
21 months ago
@audrasjb thank you for your reply. My website is live and contain mayn plugins and functionalities. Is there another method to disable the sitemap?
#5
@
21 months ago
@ema15 What @audrasjb was getting at is that the problem is likely to be caused by one of the one of the plugins that is active on your site.
Do you have an SEO plugin active? I ask because some SEO plugins have their own way of generating XML Sitemaps and the behavior you're experiencing could be caused by that SEO plugin.
#6
@
21 months ago
Hi,
I'm not using a plugin, I create my own by adding the code below to functions.php
<?php /* function to create sitemap.xml file in root directory of site */ // add_action("publish_post", "eg_create_sitemap"); // add_action("publish_page", "eg_create_sitemap"); add_action( "save_post", "eg_create_sitemap" ); function eg_create_sitemap() { if ( str_replace( '-', '', get_option( 'gmt_offset' ) ) < 10 ) { $tempo = '-0' . str_replace( '-', '', get_option( 'gmt_offset' ) ); } else { $tempo = get_option( 'gmt_offset' ); } if( strlen( $tempo ) == 3 ) { $tempo = $tempo . ':00'; } $postsForSitemap = get_posts( array( 'numberposts' => -1, 'orderby' => 'modified', 'post_type' => array( 'post', 'page' ), 'order' => 'DESC' ) ); $sitemap .= '<?xml version="1.0" encoding="UTF-8"?>' . '<?xml-stylesheet type="text/xsl" href="' . esc_url( home_url( '/' ) ) . 'sitemap.xsl"?>'; $sitemap .= "\n" . '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; $sitemap .= "\t" . '<url>' . "\n" . "\t\t" . '<loc>' . esc_url( home_url( '/' ) ) . '</loc>' . "\n\t\t" . '<lastmod>' . date( "Y-m-d\TH:i:s", current_time( 'timestamp', 0 ) ) . $tempo . '</lastmod>' . "\n\t\t" . '<changefreq>daily</changefreq>' . "\n\t\t" . '<priority>1.0</priority>' . "\n\t" . '</url>' . "\n"; foreach( $postsForSitemap as $post ) { setup_postdata( $post); $postdate = explode( " ", $post->post_modified ); $sitemap .= "\t" . '<url>' . "\n" . "\t\t" . '<loc>' . get_permalink( $post->ID ) . '</loc>' . "\n\t\t" . '<lastmod>' . $postdate[0] . 'T' . $postdate[1] . $tempo . '</lastmod>' . "\n\t\t" . '<changefreq>Weekly</changefreq>' . "\n\t\t" . '<priority>0.5</priority>' . "\n\t" . '</url>' . "\n"; } $sitemap .= '</urlset>'; $fp = fopen( ABSPATH . "sitemap.xml", 'w' ); fwrite( $fp, $sitemap ); fclose( $fp ); }
#7
in reply to:
↑ 4
@
21 months ago
Replying to ema15:
I'm not using a plugin, I create my own by adding the code below to functions.php
Earlier you said:
Replying to ema15:
My website is live and contain mayn plugins and functionalities.
So, I suspect that one of the other plugins you have on your site is overriding your use of add_filter( 'wp_sitemaps_enabled', '__return_false' )
. The most likely candidate for such a plugin is an SEO plugin...which is why I asked whether you have an SEO plugin installed.
I'll also note that I cannot replicate the behavior you describe on a fresh WP site with the TwentyTwentyThree theme and no other plugins than one that hooks wp_sitemaps_enabled
on (or before) the init
action.
Can you verify that you're not hooking wp_sitemaps_enabled
after the init
action?
In order to determine whether there really is a bug in WP core, we need more information from you, including (but perhaps not limited to):
- what plugins you have active on your site
- when you are hooking
wp_sitemaps_enabled
#8
@
21 months ago
Before creating my own sitemap, I installed XML sitemap generator for Google and yoast SEO plugins. But now they are inactive.
#9
@
21 months ago
Hi,
I tried many solutions, but nothing work. I tried to deny all users except googlebot from access wp-sitemap ofr testing, but the sitemap is alwayes accessible. Here is the code I added to .htaccess file:
RewriteEngine On RewriteCond %{HTTP_USER_AGENT} !googlebot$ [NC] RewriteRule ^wp-sitemap\.xml - [F,L]
#10
@
21 months ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
I'll close this ticket off as it doesn't look like an issue in WordPress core. @ema15 your best course of action is to eliminate other factors such as other plugins, your theme, additional rewrite rules, and the priority of hooks.
Discussion can continue on this ticket while it's closed, but this does appear to be an issue specific to your individual site.
Hello @ema15, welcome to WordPress Core Trac and thanks for opening this ticket,
Using
add_filter( 'wp_sitemaps_enabled', '__return_false' );
on a fresh WordPress install without any plugin, I wasn't able to reproduce the issue. Can you please try on a fresh WP install without any plugin, please?