Make WordPress Core

Opened 2 years ago

Last modified 3 days ago

#61293 new enhancement

Display an empty sitemap instead of 404

Reported by: Cybr Owned by:
Priority: normal Milestone: 7.2
Component: Sitemaps Version:
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

The sitemap can be empty when something filters its contents (I do that with The SEO Framework via indexability checks, such as "noindex").

When the sitemap is empty, WP_Sitemaps::render_sitemaps() currently bails to a 404.
I recommend sending an empty sitemap instead.

This change aligns with the user's expectations: They can actually see the sitemap and understand it is empty instead of "not working, eh, where do I start?".

Also, with the change, Google Search Console will say, "Sitemap can be read, but has errors" instead of "Sitemap could not be read". The former is a bit more descriptive of the situation.

Change History (12)

#1 @Cybr
2 years ago

The support topic that motivated me to create this ticket: https://wordpress.org/support/topic/sitemap-shows-nofollow-options/. We get about one or two of these every month.

Last edited 2 years ago by Cybr (previous) (diff)

This ticket was mentioned in PR #6903 on WordPress/wordpress-develop by @devansh2002.


2 years ago
#2

  • Keywords has-patch added

Removed the code block that forced a 404 response when the sitemap URL list was empty. This change allows empty sitemaps to return a valid XML structure instead of a 404 error, improving visibility for users and search engines.

This aligns with user expectations and provides clearer feedback in tools like Google Search Console.

Trac ticket: https://core.trac.wordpress.org/ticket/61293

#3 @Cybr
2 years ago

Another support topic about this confusing behavior: https://wordpress.org/support/topic/sitemap-404-error-15/.

#5 @masteradhoc
3 months ago

  • Milestone Awaiting Review7.1

This ticket was mentioned in Slack in #core by adrianduffell. View the logs.


2 months ago

#7 @adrianduffell
2 months ago

With the 7.1 beta approaching, this has a chance to be included if the PR can be reviewed in the coming days.

#8 @wildworks
2 months ago

  • Milestone 7.17.2

Punting this since the 7.1 Beta 1 release is imminent.

This ticket was mentioned in Slack in #core by adamsilverstein. View the logs.


10 days ago

#10 @westonruter
3 days ago

In 63570:

Sitemaps: Don't 404 valid sitemaps on sites with no posts.

WP::handle_404() sets a 404 when the main query matches no posts and no exception applies. Sitemap requests were never among those exceptions; they were shielded only incidentally, by falling through to is_home, and in r62664 that fallthrough was removed. A site with no published posts therefore served a complete, valid sitemap under a 404 status, which search engines discard.

Exempt sitemap and stylesheet routes there, alongside the existing admin, robots and favicon exceptions. Since handle_404() no longer decides the status for these requests, every sitemap 404 now has to be issued by WP_Sitemaps::render_sitemaps() instead: an unregistered provider, an unrecognized stylesheet type, and a route whose query vars do not survive sanitize_text_field() would each otherwise be served as a 200 on an arbitrary URL. These share a send_404() helper, which also sends the no-cache headers handle_404() was previously contributing, so an intermediary does not retain a 404 for a route that becomes valid once the site has more content.

Sitemaps disabled via the wp_sitemaps_enabled filter, and providers with an empty URL list, keep the status they already had; whether the latter should render an empty sitemap instead is #61293.

Developed in https://github.com/WordPress/wordpress-develop/pull/13247.
Follow-up to r48072, r48523, r62664.

Props iamchitti, westonruter, fernandot, wildworks, harishtewari, l1onofjudah, luksusspokoju, abrahamfariaz, andreasca, siliconforks, adamsilverstein, audrasjb, ocean90, mrkenobi.
See #39157, #61293.
Fixes #65945.

#11 @westonruter
3 days ago

In 63573:

Sitemaps: Don't 404 valid sitemaps on sites with no posts.

WP::handle_404() sets a 404 when the main query matches no posts and no exception applies. Sitemap requests were never among those exceptions; they were shielded only incidentally, by falling through to is_home, and in r62664 that fallthrough was removed. A site with no published posts therefore served a complete, valid sitemap under a 404 status, which search engines discard.

Exempt sitemap and stylesheet routes there, alongside the existing admin, robots and favicon exceptions. Since handle_404() no longer decides the status for these requests, every sitemap 404 now has to be issued by WP_Sitemaps::render_sitemaps() instead: an unregistered provider, an unrecognized stylesheet type, and a route whose query vars do not survive sanitize_text_field() would each otherwise be served as a 200 on an arbitrary URL. These share a send_404() helper, which also sends the no-cache headers handle_404() was previously contributing, so an intermediary does not retain a 404 for a route that becomes valid once the site has more content.

Sitemaps disabled via the wp_sitemaps_enabled filter, and providers with an empty URL list, keep the status they already had; whether the latter should render an empty sitemap instead is #61293.

Developed in https://github.com/WordPress/wordpress-develop/pull/13247.
Follow-up to r48072, r48523, r62664.

Reviewed by adamsilverstein.
Merges r63570 to the 7.0 branch.

Props iamchitti, westonruter, fernandot, wildworks, harishtewari, l1onofjudah, luksusspokoju, abrahamfariaz, andreasca, siliconforks, adamsilverstein, audrasjb, ocean90, mrkenobi.
See #39157, #61293.
Fixes #65945.

#12 @westonruter
3 days ago

In 63575:

Sitemaps: Don't 404 valid sitemaps on sites with no posts.

WP::handle_404() sets a 404 when the main query matches no posts and no exception applies. Sitemap requests were never among those exceptions; they were shielded only incidentally, by falling through to is_home, and in r62664 that fallthrough was removed. A site with no published posts therefore served a complete, valid sitemap under a 404 status, which search engines discard.

Exempt sitemap and stylesheet routes there, alongside the existing admin, robots and favicon exceptions. Since handle_404() no longer decides the status for these requests, every sitemap 404 now has to be issued by WP_Sitemaps::render_sitemaps() instead: an unregistered provider, an unrecognized stylesheet type, and a route whose query vars do not survive sanitize_text_field() would each otherwise be served as a 200 on an arbitrary URL. These share a send_404() helper, which also sends the no-cache headers handle_404() was previously contributing, so an intermediary does not retain a 404 for a route that becomes valid once the site has more content.

Sitemaps disabled via the wp_sitemaps_enabled filter, and providers with an empty URL list, keep the status they already had; whether the latter should render an empty sitemap instead is #61293.

Developed in https://github.com/WordPress/wordpress-develop/pull/13247.
Follow-up to r48072, r48523, r62664.

Reviewed by adamsilverstein.
Merges r63570 to the 7.1 branch.
Merged to the 7.0 branch in error in r63573 and reverted in r63574.

Props iamchitti, westonruter, fernandot, wildworks, harishtewari, l1onofjudah, luksusspokoju, abrahamfariaz, andreasca, siliconforks, adamsilverstein, audrasjb, ocean90, mrkenobi.
See #39157, #61293.
Fixes #65945.

Note: See TracTickets for help on using tickets.