Skip to content Skip to sidebar

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.

Sun Mon Tue Wed Thu Fri Sat
10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 - -
16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 - -

Supporter timezone: Asia/Jerusalem (GMT+03:00)

Tagged: 

This topic contains 7 replies, has 0 voices.

Last updated by Itamar 1 day, 4 hours ago.

Assisted by: Itamar.

Author Posts
July 30, 2025 at 10:26 pm #17283276

markusM-54

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?

July 31, 2025 at 10:33 am #17284717

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

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

Please see the attached screenshot.

By default, WordPress and WPML use the en_US English language.
If you need other custom English languages, you can follow the method described here.
https://wpml.org/errata/how-to-add-english-united-states-as-a-custom-language-to-use-as-default-or-translation-language/
You can also create custom languages in WPML -> Languages -> Edit languages. Please read about it here.
https://wpml.org/documentation/getting-started-guide/language-setup/editing-wpmls-languages-table/#add-custom-languages
Can you please tell me how you created your custom English languages?

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.

Regards,
Itamar.

2025-07-31_13-10-08.jpg
July 31, 2025 at 10:39 pm #17286824

markusM-54

Hi Itamar,

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.

hidden link

August 1, 2025 at 9:46 am #17287737

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Thanks for adding information about your case.

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.

Regards,
Itamar.

August 5, 2025 at 8:59 am #17295527

markusM-54

Hey just checking in, any update on this. Really want to get it sorted!

Thanks
Markus

August 6, 2025 at 6:40 pm #17300684

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

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.--

Regards,
Itamar.

2025-08-06_21-28-18.jpg
August 7, 2025 at 12:33 am #17301011

markusM-54

OK, I have been through the configuration on your sandbox and compared to my live site.

In your sandbox you have set the code and hreflang as the same value (i.e en-nz)

I have confirmed that whatever is set in the "code" is used as hreflang in sitemap. You can see the test one I added to your instance.

hidden link

The issue is these need to be different in our environment.

We need language to be
domain.com/nz

but hreflang tag in sitemap needs to be en-nz to be google compliant.

How do we resolve?

August 7, 2025 at 4:00 pm #17303360

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

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.

Regards,
Itamar.

2025-08-07_18-25-55.jpg