WPML
Status
Resolved
Reported for
WPML SEO 2.2.0
Resolved in
WPML SEO 2.2.2
Related plugin/theme
Yoast SEO
Topic tags
Compatibility

Overview of the issue

When using Yoast SEO with WPML SEO, you might experience an issue where hreflang tags for hidden languages still appear in the sitemap’s source code as alternate language references, even though the posts in hidden languages are correctly excluded from the sitemap index.

Workaround

Please, make sure of having a full site backup of your site before proceeding.


  • Open the …/wp-content/plugins/wp-seo-multilingual/classes/Shared/Sitemap/BaseAlternateLangHooks.php file.

  • Look for the function addAlternateLangData starting at line 59.

  • After this line:
    list( $elements, $getPermalink, $isIndexable ) = $this->getEntryHelpers( $type, $obj );
            


  • Insert the following block of code:
    // WPML Workaround for wpmlwpseo-350 - Exclude hidden language posts
    global $sitepress;
    $hidden_languages = $sitepress->get_setting( 'hidden_languages', [] );
    
    if ( $elements && !empty($hidden_languages) ) {
        foreach( $elements as $lang => $element) {
            if ( in_array( $lang, $hidden_languages ) ){
                unset( $elements[$lang] );
            }
        }
    }
            

All known issues →