Skip Navigation

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

Problem:
The client noticed an unexpected x-default tag on their pages and wondered if it was due to a recent WPML plugin version upgrade. They asked if there was a way to deactivate it through the plugin interface or if there was a hook available for controlling it programmatically.
Solution:
We confirmed that the x-default tag was indeed automatically added in the WPML version 4.5.0 and that there is no built-in option in the WPML interface to switch it on or off. However, we provided a custom hook that can be used to control the x-default tag. Here is the code that the client can use:

add_filter( 'wpml_hreflangs', 'remove_xdefault' );<br />function remove_xdefault($hreflangs){<br />    foreach ($hreflangs as $key => $lang){<br />        if ($key == "x-default"){<br />            unset($hreflangs[$key]);<br />        }<br />    }<br />    return $hreflangs;<br />}

This code should be added to the theme's functions.php file or a custom plugin to remove the x-default tag.

Please note that this solution might be irrelevant if it's outdated or not applicable to your case. If the issue persists, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket.

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 5 replies, has 2 voices.

Last updated by Mihai Apetrei 2 years, 10 months ago.

Assisted by: Mihai Apetrei.

Author Posts
January 19, 2022 at 11:12 am #10382825

danielH-111

we are suddenly seeing x-default tag in our pages, Is this happened due to version upgrade?
How we can deactivate this? is that possible through plugin interface? if yes then please guide.

Thanks

x-default-duplicate.png
January 19, 2022 at 10:53 pm #10388827

Mihai Apetrei
Supporter

Languages: English (English )

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

Hi there.

I would like to request temporary access (wp-admin and FTP) to your site to take a better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.

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 make a backup of the site files and database before providing us access.

- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box.

The private box looks like this: hidden link

I will be waiting for your response.

Kind regards,
Mihai Apetrei

January 20, 2022 at 5:21 am #10389829

danielH-111

Hello Mihai,

Prior sharing details, I would like to repeat my question.

1) Is the new version upgrade has x-default added? is It auto embedded?

2) In upgrade version of Plugin, Do we have option to switch on/off the x-default tag?

Appreciate your response back.

Thanks

January 20, 2022 at 6:12 pm #10396821

Mihai Apetrei
Supporter

Languages: English (English )

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

Hi there and welcome back.

1. I checked with the developers and yes, this was added in version 4.5.0

Here's an explanation for x-default:
hidden link

Also from Google:
hidden link

It's the value we set for the hreflang attribute of <link> for the most universal language of the site, that is when the site does not have a language matching the visitor's browser languages.

2. There is no built-in option to switch it on or off.

I hope that you will find this answer helpful.

Mihai

January 24, 2022 at 10:16 am #10416409

danielH-111

Hi Mihai,

Thanks appreciate reply and answer back.

Since its clarified and confirmed that x-default tags are auto inserted and has no control through interface of WPML.

So I would like to know is there any hook through which we can control these through programming?

Appreciate your help and response in this.

Thanks

January 26, 2022 at 2:19 pm #10437001

Mihai Apetrei
Supporter

Languages: English (English )

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

Hi there.

The hook is "wpml_hreflangs".

Here is a proof of concept code:


add_filter( 'wpml_hreflangs', 'test' );
function test($hreflangs){
    foreach ($hreflangs as $key => $lang)
    {
        if ($key == "x-default"){
            unset ($hreflangs[$key]);
        }
    }
    return $hreflangs;
}

This should unset the x-default key.

That should help.

Mihai