Filter Canonical not working for Sitemap XML
- [ ] I've read and understood the contribution guidelines.
- [ ] I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened.
I am using the wpseo_canonical filter in the way it's also suggested on https://yoast.com/help/canonical-urls-in-yoast-seo/ and our SEO department reported URLs in the sitemap XML that actually have cross domain canonicals.
Please describe what you expected to happen and why.
Properly stored cross domain canonicals (within the yoast indexables) will result in a removal of the very entry from the sitemap. According to our SEO department this is required for better use of the crawl budget among other reasons, and yoast SEO does this already for unfiltered ones.
I would expect a comparable behavior for filtered canonicals, alternatively I would welcome a replacement of the filter, with a functionality to properly store canonicals within yoast indexables. With the documented filter, it is nevertheless broken.
How can we reproduce this behavior?
- Use
wpseo_canonicalto return a canonical on a different domain. - Check sitemap.xml (result will be that the local unfiltered path is still there)
- Remove the Filter
- Use the WordPress Backend to store the same cross domain canonical (stored in post meta and yoast canonicals)
- Check sitemap.xml (result will be that the post is gone from the sitemap, since it's a remote canonical)
Technical info
- If relevant, which editor is affected (or editors):
- [ ] Classic Editor
- [ ] Gutenberg
- [ ] Classic Editor plugin
- Which browser is affected (or browsers):
- [ ] Chrome
- [ ] Firefox
- [ ] Safari
- [ ] Other
Used versions
- WordPress version: All
- Yoast SEO version: All
- Gutenberg plugin version:
- Classic Editor plugin version:
- Relevant plugins in case of a bug:
- Tested with theme: Self coded, not relevant here
If I understood correctly when you replace the canonical on a page using the wpseo_canonical filter, the relevant page URL remains on the sitemap. However, if you add the canonical using the Yoast SEO meta box, the relevant page URL disappears from the sitemap. Did I get that right? If so, do you want to have the relevant page URL in the sitemap or do you want the relevant page URL disappears from the sitemap? I am just trying to understand the whole context before I could confirm anything.
Hello iamazik,
i have exactly the same problem. My Woordpress Website runs with translatepress and yoast Premium in german and english language. I got in all english canonical links ( source code of english website) a trailing slash at the end. It was possible to delete the wrong slash with the filter add_filter( 'wpseo_canonical', '__return_false' ); . But in the sitemap its still there. I opend allready a ticket and I am in contact with the premium support. But until now, no solutions.
@iamazik that is correct.
Using the filter only changes the canonical tag, and has no impact on the sitemap.
I understand that adding the filter to the sitemap is likely not clever, since this will likely cause load issues and timeouts for the sitemap.
So possibly the solution is to either add a warning to the documentation of the filter, or get rid of the filter altogether and rather give some proper programmatic way of setting it, in both post meta and the indexable table.
@apermo thanks for clarifying it. I will mark it as a bug so we can have a fix for it! Moved to internal repository https://yoast.atlassian.net/browse/IM-1971