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

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

The problem: The hreflang value is empty in all our pages like the following:

The solution: In this case, the table wp_icl_languages got corrupted. Restoring the table resolved the problem.

This topic contains 4 replies, has 2 voices.

Last updated by Richard 4 years, 11 months ago.

Assigned support staff: Dat Hoang.

Author Posts
November 11, 2014 at 12:37 pm #509482

Richard

I was looking at my google webmaster's info, and went to the International Targeting section for my site for the first time.

It said:

Your site has no hreflang tags.
Google uses hreflang tags to match the user's language preference to the right variation of your pages.

I thought this was strange, since I know I've seen the hreflang header tags in my pages before.

I go to a translated page, and low a behold, the hreflang tag is empty. The href is correct, but the hreflang is empty....

<link rel="alternate" hreflang="" href="hidden link" /><link rel="alternate" hreflang="" href="hidden link" />

I do a string search through wpml code and find the relevant code. It seems you have a bad query in

function get_language_tag( $code )
	{
		global $wpdb;
		static $all_tags = null;

		if ( is_null( $code ) )
			return false;
		if ( $tag = wp_cache_get( 'icl_language_tags_' . $code ) ) {
			return $tag;
		}

		if($all_tags==null) {
			$all_tags_data = $wpdb->get_results( "SELECT code, tag FROM {$wpdb->prefix}icl_languages" );
			foreach($all_tags_data as $tag_data) {
				$all_tags[$tag_data->code] = $tag_data->tag;
			}
		}

		$tag = $this->get_locale( $code );
		if($all_tags) {
			$tag = isset($all_tags[$code]) ? $all_tags[$code] : false;
			if ( $tag ) {
				wp_cache_set( 'icl_language_tags_' . $code, $tag );
			}
		}
		return $tag;
	}

The query

$all_tags_data = $wpdb->get_results( "SELECT code, tag FROM {$wpdb->prefix}icl_languages" );

Is wrong. There is NO tag column in the icl_languages table.

This query is returning

code tag
en
es
de
fr
ar
bs
bg
ca
cs
sk
cy
da
el
eo
et
eu
fa
fi
ga
he
hi
hr
hu
hy
id

So this function return empty string for everything.

Please fix this.

Thank you,
Rich

November 11, 2014 at 12:40 pm #509483

Richard

Sorry, here is the complete query result I get. phpMyAdmin didn't return all the rows. I don't want you to think I have a broken install.

SQL query: SELECT code, tag FROM

wp_icl_languages

LIMIT 0, 100 ;
Rows: 64

code tag
en
es
de
fr
ar
bs
bg
ca
cs
sk
cy
da
el
eo
et
eu
fa
fi
ga
he
hi
hr
hu
hy
id
is
it
ja
ko
ku
la
lv
lt
mk
mt
mo
mn
ne
nl
nb
pa
pl
pt-pt
pt-br
qu
ro
ru
sl
so
sq
sr
sv
ta
th
tr
uk
ur
uz
vi
yi
zh-hans
zu
zh-hant
ms

November 11, 2014 at 12:46 pm #509489

Richard

Sorry again. There is in fact a tag column in the table. It's just that column is completely empty in my install. Should it be?

I just don't get it.

The function head_langs()

Does

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' ] ) );
}
}

It seems to me, we already have the code (ie. zh-hans, zh-hant). Shouldn't that be what is inserted into hreflang? The call to get_language_tag($code), makes it be empty string...

Rich

November 12, 2014 at 7:12 am #509900

Dat Hoang

I'm not sure where the problem is now because I don't get it in my testing site.

Your WPML versions look good.

I think this may a conflict between WPML and one of your plugins/theme.

If you disable all non-related WPML plugins, switch to one of default themes, the problem persists or not?

November 12, 2014 at 12:31 pm #510170

Richard

I looked further into the wpml setup code, and I determined that my icl_languages table was corrupted. It was missing data from both the default_locale, and tag columns.

I'm not certain, but because wpml 3.1.8.2 was giving me problems and breaking m wp-admin pages (I filed another bug for that), I had to manually deactivate the wpml plugin by removing the plugin folder my site. I tried several times to get 3.1.8.2 to work, so maybe one of the times it reactivated, something weird happened. I have no idea.

Anyway, I deactivated the wpml plugin. I renamed my icl_languages table to icl_languages_out. I then reactivated wpml.

On reactivation, wpml recreated the icl_languages table. I inspected this, and confirmed that the missing data from the two columns was now present.

This is what my table returns now:

SQL query: SELECT code, tag FROM

wp_icl_languages

LIMIT 0, 100 ;
Rows: 64

code tag
en en-US
es es-ES
de de-DE
fr fr-FR
ar ar
bs
bg bg-BG
ca ca
cs cs-CZ
sk sk-SK
cy cy
da da-DK
el el
eo eo
et et
eu eu
fa fa-IR
fi fi
ga
he he-IL
hi
hr hr
hu hu-HU
hy
id id-ID
is is-IS
it it-IT
ja ja
ko ko-KR
ku ku
la
lv lv
lt lt
mk mk-MK
mt
mo
mn
ne
nl nl-NL
nb nb-NO
pa
pl pl-PL
pt-pt pt-PT
pt-br pt-BR
qu
ro ro-RO
ru ru-RU
sl sl-SI
so
sq
sr sr-RS
sv sv-SE
ta
th th
tr tr
uk uk-UA
ur
uz uz-UZ
vi vi
yi
zh-hans zh-CN
zu
zh-hant zh-TW
ms ms-MY

I changed the active flags back to the ones I previously had for English, and the 2 Chinese languages.

My hreflang tags are now fixed.

Now showing.

<link rel="alternate" hreflang="en-US" href="hidden link" /><link rel="alternate" hreflang="zh-CN" href="hidden link" /><link rel="alternate" hreflang="zh-TW" href="hidden link" />

In conclusion, a the icl_languages table was somehow damaged, and I fixed this myself.

Rich