wordpress-seo
wordpress-seo copied to clipboard
Latest update (21.9) breaks custom sitemap
- [x] I've read and understood the contribution guidelines.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened
We have some feeds coming into various sites and use the 'wpseo_sitemap_index' filter to add our custom generated XML files to the index.
We do this by adding a rewrite rule template_redirect with a custom variable. EG:
function rewrite_rules() {
add_rewrite_rule( '^custom-sitemap\.xml$', 'index.php?xml_custom_sitemap=true', 'top' );
}
add_action( 'init', 'rewrite_rules', 1 );
and then in the template_redirect, we check for the variable before generating the XML:
global $wp_query;
if ( ! empty( $wp_query->query_vars['xml_custom_sitemap'] ) && $wp_query->query_vars['xml_custom_sitemap'] === 'true' ) {
When I roll back to the last version and dump the query vars I can see our custom variable:
array(66) {
| ["xml_sale_yachts_sitemap"]=>
| string(4) "true"
After updating the plugin, this variable gets stripped and replaced with something added by Yoast:
array(67) {
["sitemap"]=>
| string(10) "sale-yacht"
| ["sitemap_n"]=>
| string(0) ""
I'm not sure why or how Yoast is doing this, since the template_redirect is technically nothing to do with the plugin other than the URL to this page being referenced in the sitemap.
It appears to be a breaking change.
Maybe the new Yoast variables could be added without stripping any others?
Hi @robwent
Thanks for using the Yoast SEO plugin and for creating the issue. In version 21.9, we improved the sitemap rewrite rules mechanism. You can find out the PR here. and can read about it in our changelog.
So, can you please let us know the exact steps and changes we need to make to the code to replicate this error at our end?
I saw the filter for sitemaps in the changelog but not the rewrite rules part. The PR looks like it shouldn't affect other plugins though.
I made a quick plugin to demonstrate: https://gist.github.com/robwent/be32ea0cc824ce90ddc31447ebf67ea4
This adds my-custom-sitemap.xml to the index.
Install and enable it together with Yoast 21.8.1 and save permalinks.
If you navigate to https://example.com/my-custom-sitemap.xml you should see the query vars dumped with a custom one called xml_my_custom_sitemap:
If you then update Yoast, the page will return a 404 error. In the plugin file, uncomment line 36 and reload the page.
The custom query var is removed and replaced with 2 new vars:
This actually makes it easier to create sitemaps since the custom rewrite rule no longer appears to be needed, but changing query vars added by other plugins could have additional unwanted effects.
Hi @robwent
Thanks for using the Yoast SEO plugin and for reaching out to us.
Yes, you are right with version 21.9; we made changes on how the custom sitemaps are generated. In version 21.9, we are processing all the custom sitemaps with the *-sitemap.xml suffix to have the Yoast SEO sitemap styles. As the sitemap you have added also has the same suffix custom-sitemap.xml, it returns a 404 error.
I apologize that this was not updated within the documentation; however, our team will update this with more details in the coming days.