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.

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

Problem: How can I add the x-default hreflang tag? Solution: Try the code that you can find here:

This topic contains 8 replies, has 6 voices.

Last updated by John Michael 3 weeks, 3 days ago.

Assigned support staff: Vincenzo.

Author Posts
March 23, 2018 at 7:51 am #1554636

John Michael


I would like to know how can i setup "x-default hreflang" ? I spent a lot of time looking for this but cant find it.

Second question i have is i got a warning below from WPML but it doesnt seems to be an issue as things are working well on my site.

Thx for your advice.

March 26, 2018 at 12:39 pm #1556554


Languages: English (English ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hello, thank you for contacting WPML Support!
I will take care of your ticket.

1. If the "Different languages in directories" option works, you can ignore that notice.

2. To add the x-default hreflang. you can try adding the following example code to the functions.php file of your theme, preferably to a child theme.

/* ---------------------------------------------------------------------------
 * Set hreflang="x-default" with WPML
 * --------------------------------------------------------------------------- */
add_filter('wpml_alternate_hreflang', 'wps_head_hreflang_xdefault', 10, 2);
function wps_head_hreflang_xdefault($url, $lang_code) {
    if($lang_code == apply_filters('wpml_default_language', NULL )) {
        echo '<link rel="alternate" href="' . $url . '" hreflang="x-default" />'.PHP_EOL;
    return $url;

Please note that this code is supplied "AS IS" without any warranties and support.

Let me know if this solves the issue or if you need further details.

Thank you

Related documentation:

April 11, 2018 at 11:58 pm #1602625


Well, it would sure be nice if WPML could do the right thing here are insert this HTML automatically.

Can you add this as a feature request?

Jeff Crawford
hidden link

July 19, 2018 at 10:39 am #2534465


Hello @vincenzo-c,

did you consider to add in the core the x-default functionality?


July 19, 2018 at 11:10 am #2534542


Languages: English (English ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)


I'm glad to inform you that this was already on our list of features requests and I just added your vote to it.
When exactly our developers will add this new feature is not up to us to determine.

Thank you

December 23, 2018 at 8:35 am #3028427


Any update on this?

February 14, 2019 at 8:32 pm #3201759


Thanks Vincenzo - the code works with bridge theme (child theme) perfectly - just by copy pasting! thanks!!!

May 25, 2019 at 2:40 pm #3889581


Hello @vincenzo-c,

I would like to I ask you if x-default hreflang is now part of WPML's core.

My best

September 22, 2019 at 5:22 am #4617341

John Michael


Any update on this ?

x-default is part of Google's guidelines on hreflang implementation.

This is crazy it's not implemented yet.