This thread is resolved. Here is a description of the problem and solution.
Problem:
The client is experiencing an issue with the WPML SEO plugin where the Yoast SEO sitemaps are showing hreflang tags for hidden or disabled languages (ES, FR) even though these languages are not currently active on their website.
Solution:
We recommend modifying the plugin's codebase as a temporary workaround:
1. Open the file
/plugins/wp-seo-multilingual/classes/Shared/Sitemap/BaseAlternateLangHooks.php
.
2. Locate the
addAlternateLangData
function around line 59.
3. After the line
list( $elements, $getPermalink, $isIndexable ) = $this->getEntryHelpers( $type, $obj );
, insert the following code:
// 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] ); } } }
This code will exclude posts in hidden languages from appearing in the sitemap's alternate language data.
Please note that this solution might become outdated or may not apply to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket at WPML support forum.
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.