WPML
Status
Resolved
Reported for
WPML SEO 2.2.4
Resolved in
2.2.5
Related plugin/theme
Rank Math SEO
Topic tags
Compatibility

Overview of the issue

When using Rank Math or Yoast SEO with WPML SEO, the alternate links in the source code from the sitemap may incorrectly display the translated homepage URL with an internal permalink (e.g. /es/home/) instead of the expected language root URL (e.g. /es/). This does not affect the frontend display, where canonical and hreflang links appear correct.

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 61.

  • Replace:
    $link[ self::KEY ][ $lang ] = apply_filters( 'wpml_permalink', $link['loc'], $lang );
            


  • With:
    $link[ self::KEY ][ $lang ] = apply_filters( 'wpml_permalink', $link['loc'], $lang, true );
            

  • Repeat the same operation on line 89.

  • Replace:
    return apply_filters( 'wpml_permalink', $getPermalink( $id ), $language );
            


  • With:
    return apply_filters( 'wpml_permalink', $getPermalink( $id ), $language, true );
            

After applying these changes, you need to rebuild your sitemaps:

  • For Rank Math: Go to “Rank Math > Sitemap Settings”, change the “Links per sitemap” value, save the settings (you can revert to your preferred value afterwards).
  • For Yoast SEO: Follow this tutorial to regenerate sitemaps.

All known issues →