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: https://wpml.org/forums/topic/x-default-an-other-issue/#post-1556554

This topic contains 6 replies, has 6 voices.

Last updated by aaronB-11 10 months ago.

Assigned support staff: Vincenzo.

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

John Michael

Hello,

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

Vincenzo
Supporter

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:
https://codex.wordpress.org/Child_Themes

April 11, 2018 at 11:58 pm #1602625

jeffreyC-2

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

encodia

Hello @vincenzo-c,

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

Regards

July 19, 2018 at 11:10 am #2534542

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Hello,

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

tobiasH-13

Any update on this?

February 14, 2019 at 8:32 pm #3201759

aaronB-11

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