Resolved
Reported for: WPML SEO 2.2.4
Resolved in: 2.2.5
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.
Hey guys,
that fix did it. But please be more precise.
On line 89 there is:
return apply_filters( ‘wpml_permalink’, $getPermalink( $id ), $language );
This should be replaced by:
return apply_filters( ‘wpml_permalink’, $link[‘loc’], $lang, true );
So please don’t do the same operation as on line 61 where you need to replace the full thing.
Best regards!
Hi Valentin,
You’re right, since line 89 also uses the ‘wpml_permalink’ hook, you should add the true argument there as well. I’ll update the errata. Thanks for pointing that out!