- Status
- Resolved
- Reported for
- WPML Multilingual CMS 3.3.6
- Resolved in
- 3.3.6
Overview of the issue
The hreflang meta tags may be missing from the page header. This is happening since WPML 3.3.6, in combination with themes or plugins which are loading WPML too soon.
WPML should include <link hreflang=”lang”> tags in your sites header section. This is missing in some sites using WPML 3.3.6 and in combination with some plugins or themes. The problem happens because WPML is attempting to output these tags early in the header, but other plugins are causing a race condition, triggering WPML too early. You may receive an email from Google Webmaster tool, saying “Incorrect hreflang implementation”.
The complete description of this functionality appears in Google’s content guidelines for language and regional URLs.
Workaround
To fix this in WPML 3.3.6:
- Open the file
sitepress-multilingual-cms/sitepress.class.php - Scroll down to the bottom of this file, where you must see this:

- Replace this line:
add_action( 'wp_head', array( $this, 'head_langs' ), 1 ); - With:
add_action( 'wp_head', array( $this, 'head_langs' ) ); - The final version of this code must look like that:

- Save the file
In the next version of WPML, the same fix will be applied.
The code at step #3 was meant to have the hreflang meta tags printed as early as possible, but this cause issues with some themes and plugins.
If you still want to have the hreflang meta tags printed as early as possible, you can apply a more complex solution. Add this code to your theme’s functions.php file:
function my_handle_head_hreflang() {
global $sitepress;
$settings = $sitepress->get_settings();
if ( $settings[ 'seo' ][ 'head_langs' ] ) {
remove_action( 'wp_head', array( $sitepress, 'head_langs' ) );
add_action( 'wp_head', array( $this, 'head_langs' ), 1 );
}
}
add_action('wpml_loaded', 'my_handle_head_hreflang');