Open
Reported for: WPML SEO 2.2.4
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 ); - Do the same operation on line 89.
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.