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

0% of people find this useful.

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.

Our next available supporter will start replying to tickets in about 6.97 hours from now. Thank you for your understanding.

This topic contains 11 replies, has 9 voices.

Last updated by kristianW-2 6 months, 2 weeks 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!!!

May 25, 2019 at 2:40 pm #3889581

encodia

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

Hello,

Any update on this ?

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

This is crazy it's not implemented yet.

Thx

December 9, 2019 at 8:24 pm #5095885

Kamil

When this will be implemented in WPML? It is hard to add? This is simply solution and we need to wait one year or more?

February 25, 2020 at 10:18 am #5561189

romainC-16

Hello,

I came here because I realised the x-default attibute is not generated natively.
As I have read a lot of directive advising to add it I wonder how it is possible to have to add this code snippet manually in the functions file in order to implement it.

Why, two years after the topic started, is it still not implemented in the core ?

I don't think it is a hard thing to do, I guess there might be a pragmatic/authority reason for WPML dev not to support it by default ? What is this reason ?

Unlike the advices I found, do you think it is bad pratice to add the x-default attribute inside pages ?
Can you update on it ?
Should we add this snippet or not ?

March 8, 2020 at 3:37 pm #5643089

kristianW-2

gettting warnings for missing x-default ... and link to google:

The new x-default hreflang link signals our algorithms that the site is not targeted to users of a certain language or location. At the same time, the page is considered the default page, unless there is a more suitable website.
- Google Webmaster Headquarters Blog

do I still need to implement the x-default manually (child.php)?
regards, K