Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client needs an action or filter for the HREFLANG tag to check if the URL matches the canonical URL and add or remove the HREFLANG tags based on certain conditions.

Solution:
We currently do not have a filter that meets these specific requirements. To achieve this, custom code is necessary. We recommend using the code provided in the following WPML support forum thread as a starting point for your custom solution.

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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Shekhar Bhandari 12 months ago.

Assisted by: Shekhar Bhandari.

Author Posts
December 4, 2023 at 11:25 am #14985947

dennisv-7

Is there a action or filter for the HREFLANG tag in which I can check if the URL is or isn't matching the canonical URL? In which I can accordingly add or remove the HREFLANG tags.

I found many other support tickets about editing and removing the hreflang. And I only found the option remove for all pages and languages. But I only want to remove it when certain conditions are met.

December 5, 2023 at 9:40 am #14994975

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Greetings,

We appreciate you reaching out to WPML support, and I'm here to assist with your inquiry.

Regrettably, we currently lack a filter that aligns with your specific requirements. Therefore, achieving this would necessitate the implementation of custom code.

I believe the code shared in the following link can serve as a valuable starting point for your needs: https://wpml.org/forums/topic/hreflang-x-default-is-missing-from-some-pages-2/#post-11625629

Let us know if this proves helpful.

Best regards.

December 5, 2023 at 2:21 pm #14999191

dennisv-7

Thank you! the code from that support ticket helps me a lot. With that filter I've made the custom code. And it is working perfectly.