Sitemaps: Don't return a 404 status for valid sitemap requests when the main query has no posts - #13247
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Ticket
Trac ticket: https://core.trac.wordpress.org/ticket/65945
Summary
/wp-sitemap.xmlrenders correct XML but responds with HTTP 404, so search engines discard it.WP::handle_404()404s the main query when it has no posts and no exception applies. Sitemap requests aren't in that list — they were only shielded by falling through tois_home = true, which changeset 62664 (#51542, #51543) correctly removed.Changes
WP::handle_404()— exempt sitemaps alongside the other machine-readable endpoints. Placed in the first branch rather than next tois_feed(), since provider routes mappagedfrom the URL and so never reach theelseif ( ! is_paged() )branch.WP_Sitemaps::render_sitemaps()— 404 explicitly for an unregistered provider, which previously relied onhandle_404()doing it.Intentional 404s are unaffected — sitemaps disabled and empty URL lists (#61293) call
set_404()directly, later in the request.Test
New tests/phpunit/tests/wp/handle404.php (12 tests): index, provider, paged, taxonomy, user and stylesheet routes with no posts, plus guards that unknown URLs and unregistered providers still 404.
--group sitemaps--group wp --group query --group feed --group canonical --group rewriteScreenshots
NA
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Root-cause investigation, tracing history, and drafting the fix and tests.