[Resolved] hreflang showing incorrect value in Rank Math sitemap
This thread is resolved. Here is a description of the problem and solution.
Problem: You are experiencing an issue where incorrect hreflang tags ('nz' and 'au' instead of 'en-nz' and 'en-au') are being added to your sitemap when using WPML with RankMath. Solution: 1. Open the file:
4. Save the changes. Ensure you make a full site backup before proceeding. Additionally, clear the RankMath sitemap cache by changing the "Links per sitemap" setting in "RankMath> Sitemaps settings" and saving the changes. For more details, visit our errata page: https://wpml.org/errata/wpml-seo-incorrect-hreflang-value-in-sitemaps/. This issue has been resolved in WPML SEO version 2.2.3. So the suggested workaround is not needed anymore if you can update to WPML SEO 2.2.3.
If this solution does not apply to your case, or if it seems outdated, we recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket at WPML support forum.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Background of the issue:
I have recently moved to WPML and am trying to resolve an issue where incorrect hreflang tags are being added to the sitemap. I raised this with RankMath, and they indicated that WPML is responsible for inserting the hreflang tags. You can see the sitemap output here: hidden link and the languages screen from WPML with the correct hreflang codes here: hidden link. The issue can be seen on this page: hidden link.
Symptoms:
In the sitemap, hreflang is showing 'nz' and 'au' instead of 'en-nz' and 'en-au' as defined in WPML.
Questions:
Why are the incorrect hreflang tags being added to the sitemap?
How can I ensure the correct hreflang codes from WPML are reflected in the sitemap?
I can see this problem on your site map. We might be looking here at a compatibility issue with the Rank Math plugin. But I'm unsure of that yet. The option to have the HREFLANG in the site's map is relatively new. However, before proceeding with checking the compatibility issue with Rank Math, I was trying to replicate this problem on a fresh WordPress test site. I created a custom English language during the setup wizard. However, I get different results from you. I get the language codes as follows:
English (United Kingdom) = en-gb
English (New Zealand) = en-nz
English (Australia) = en-au
When I look at your hidden link">screenshot, I notice another thing that is out of the ordinary. It is not possible to remove the custom languages. Please see the red X icons on my screenshot. This makes my question about how you created the languages even more valid. It will help me proceed with this case.
We migrated from Polylang, As part of the migration, I needed the default language to be en-GB - so I removed and recreated all languages via the WPML -> language page. I then ran the polylang migration tool. Interestingly the hreflang tags are correct in the pages...just not in the sitemap. I can remove custom langauges...see screenshot below. I just don't want to as I've got hundreds of pages linked as translations.
Thanks for sending a screenshot that shows the option to delete the custom language. Of course, you should not delete the custom languages!
I can see that the HREFLANG tags on the page are correct. This is a good sign. I wonder how it shows on the pages and also on the sitemap. I mention this because recently we have changed this from showing on pages to showing on the sitemaps, if the Rank Math or Yoast SEO plugins are installed.
Further questions, I want ot ask.
Did you have Rank Math installed also when you used Polylang?
If so, do you remember if the problem was present also then?
At the moment, I suspect two possible causes.
1. A compatibility problem with the HREFLANG option and Rank Math.
2. A problem that occurred when migrating from Polylang to WPML.
I will investigate this issue on my test site by installing Rank Math and seeing if the problem also occurs there. If it happens, I'll escalate this issue to our compatibility team. Otherwise, I'll let you know how we will proceed with this issue.
Please note that I'll be able to get back to you about this issue early next week. Meanwhile, please feel free to answer my questions.
I was unable to replicate this problem on a fresh WordPress installation with WPML and its add-ons, and Rank Math + Pro. You can check my test site here.
hidden link
With this link, you'll be logged in directly.
On the Rank Math sitemap, the hreflang shows correctly. For example, see here:
view-source:hidden link
Please see the attached screenshot.
Please check the settings on my test site and compare to your site. Hopefully you will be able to find where the fault is and correct it on your site. It is also worth trying to save the Rank Math and permalinks settings again and checking if it helps.
Otherwise, it appears to be a specific problem on your site that we need to investigate further. The problem might be due to the migration from Polylang, or it might not be related to WPML.
So if you need further help with this, please share the access details to your site with me. I'm enabling a private message for the following reply. Also, in case needed, please allow me to take a copy of your site. For this, I must install a plugin like Duplicator or All In One Migration. Please let me know if you agree. Privacy and Security Policy
We have strict policies regarding privacy and access to your information. Please see: https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/ **IMPORTANT**
- - Please backup the site files and database before providing us access. --
-- If you have a staging site where the problem can be reproduced, it is better to share access to the staging site.--
Thanks! It appears you helped us spot a compatibility problem.
The regular pages and posts get the hreflang from the 'hreflang' field in the languages' table. Please see the attached screenshot. It is your test language 'en-test' that is showing the expected 'hreflang' value from the 'hreflang' field. However, Rank Math sitemaps get it from the language code. I'll escalate this issue to our compatibility team and keep you updated here on any news regarding this issue.
4. Save the change.
**** Important! Please make a full site backup (files and DB) before you proceed with those steps****
Our compatibility developers also brought the following to our attention.
Please note that RankMath sitemaps have cache. I couldn't find a purge button, but I was able to purge them by changing the "Links per sitemap" setting in "RankMath> Sitemaps settings" and saving changes.
This issue has been escalated to our developers. They will fix this problem in the WPML SEO files. When the version with the fix is released, I'll update you here.
Thanks, that has resolved the issue with hreflang in sitemap. I am also getting a strange situation where default language will just disappear. I'll raise a separate ticket for that.
Thanks for confirming that the workaround fixed the issue.
I'm setting this ticket to 'Escalated to the developers' so we can inform you when the version with the fix is released.
Thanks for opening a new ticket with the other issue.