Skip Navigation

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 7.51 hours from now. Thank you for your understanding.

This topic contains 6 replies, has 4 voices.

Last updated by Iggy 7 years, 4 months ago.

Assigned support staff: Denise.

Author Posts
May 15, 2014 at 12:18 pm #401076



according to
hidden link
hidden link

for multi-language sites there should be also the annotation of the default language.
But it looks like it is missing from my site.

Why WPML is not adding it? How to add it?

May 16, 2014 at 9:09 am #401575


The x-default feature is not yet supported through WPML. I have submitted a feature request with our developers and this may be included in a future release

x-default must be used for these pages that don't have, or are not supposed to have a translation. For instance, is the default page that redirects users to the localized version of the site (automatically, or through a language switcher)

In WPML this is the "root" page, set in the Language setting. The typical default page should not have the x-default attribute because it's a localized page.

WPML uses the "canonical header" instead to tell Google where the original content is. It can be enabled under Languages -> SEO Options by selecting "Display alternative languages in the HEAD section."

If you want to add the x-default yourself you can do the following steps:

1. Open wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php

2. Search for function head_langs() (around line 9900)

3. Look at this part of the code:
if ( $is_valid ) {
foreach ( $languages as $code => $lang ) {
printf( '<link rel="alternate" hreflang="%s" href="%s" />' . PHP_EOL, $this->get_language_tag( $code ), str_replace( '&', '&', $lang[ 'url' ] ) );

4. change it to:
if ( $is_valid ) {
foreach ( $languages as $code => $lang ) {
if($code = $this->get_default_language()) {
printf( '<link rel="alternate" hreflang="x-default" href="%s" />' . PHP_EOL, str_replace( '&', '&', $lang[ 'url' ] ) );
} else {
printf( '<link rel="alternate" hreflang="%s" href="%s" />' . PHP_EOL, $this->get_language_tag( $code ), str_replace( '&', '&', $lang[ 'url' ] ) );

May 16, 2014 at 10:53 am #401649


Thank you for your kind and detailed answer. However I know have doubts.
Can you please suggest whether my site needs the x-default?

I have a, it's main/default language is Polish.
Then I have the translations in in English.


May 16, 2014 at 12:06 pm #401715


Your Welcome Sergio,

You will have to make that decision based on your content. Google only recommends x-default if your page dynamically produces localized worldwide content.

X-default affects where visitors who do not use either Polish or English will be directed.

"The same annotation applies for homepages that dynamically alter their contents based on a user’s perceived geolocation or the Accept-Language headers. The x-default hreflang value signals to our algorithms that such a page doesn’t target a specific language or locale." - hidden link

More info: hidden link

May 16, 2014 at 12:09 pm #401717


Thank you. I think it's clear now.

April 14, 2017 at 11:37 am #1254368

/* ---------------------------------------------------------------------------
 * Set hreflang="x-default" according to Google content guidelines 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" />';
	return $url;
October 6, 2017 at 1:22 pm #1393678


@WP-Stars Thank you very much! Perfect!