Zum Inhalt springen Zur Seitenleiste springen

Resolved

Reported for: WPML SEO 2.2.4

Resolved in: WPML SEO 2.2.5

Topic Tags: Compatibility

Overview of the issue

When using RankMath SEO with WPML, you might experience an issue where the homepage URLs in the sitemaps‘ source code <xhtml:link rel="alternate" hreflang="..."> are incorrect for secondary languages. Instead of showing the language-specific homepage (e.g., domain.com/?lang=es), the sitemap outputs a full page URL (e.g., domain.com/page-slug/?lang=es).

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 line 88.
  • Replace:
    			$mapPermalink = function ( $id, $language ) use ( $getPermalink ) {
    				return apply_filters( 'wpml_permalink', $getPermalink( $id ), $language );
    			};
            
  • With:
    			$mapPermalink = function ( $id, $language ) use ( $getPermalink ) {
    
    				// WPML Workaround for wpmlsupp-13368 
    				$front_id = (int) get_option( 'page_on_front' );
    				if ( $front_id ) {
    					$default_lang = apply_filters( 'wpml_default_language', null );
    					$id_in_default = (int) apply_filters( 'wpml_object_id', (int) $id, 'page', false, $default_lang );
    					if ( $id_in_default && $id_in_default === $front_id ) {
    						return apply_filters( 'wpml_permalink', trailingslashit( home_url() ), $language );
    					}
    				}
    
    				return apply_filters( 'wpml_permalink', $getPermalink( $id ), $language );
    			};
            
  • Rebuild the sitemaps: Go to „Rank Math > Sitemap Settings“, change the „Links per sitemap“ value, and save.