Hello,
We apologize for the issue you are facing with your sitemap. It seems that the incorrect entry for your Spanish homepage in the sitemap is a common issue when using WPML with Rank Math.
To resolve this, you can add a specific piece of code to your theme’s rank-math.php file. This code will help ensure that the correct homepage URLs are generated in the sitemap. Here’s what you can do:
-
Access your theme files via FTP or your hosting file manager.
-
Locate the rank-math.php file in your theme’s directory.
-
Add the following code snippet to that file:
// Custom code to fix incorrect entries for translated homepages
add_filter( 'rank_math/sitemap/entry', function( $entry, $post ) {
if ( $post->post_type === 'page' && $post->post_name === 'home-i' ) {
$entry['loc'] = home_url( '/es/' ); // Change this to your correct homepage URL
}
return $entry;
}, 10, 2 );
-
Save the changes and check your sitemap again.
If you continue to experience issues, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further. Thank you for raising this concern!
Sources:
Multilingual SEO with Rank Math SEO & WPML » Rank Math
I have placed the code in rank-math.php file, but the problem persists. I have tried different ways, and nothing works.
Hello,
We’ve checked your sitemap, and the correct homepage URL is already shown

If you’re still seeing the incorrect URL, please clear your website’s cache or check using a different browser.
Looking forward to helping you.
Hello,
Although Rank Math only generates the primary language of the site for the sitemap, yes, this setup is also fine. This helps search engines index the content for each language correctly.
Don’t hesitate to get in touch with us if you have any other questions.
Hello,
We’re delighted to hear that this issue has been resolved. We appreciate your feedback.
This ticket will be closed now, but if you ever have another question or need any help in the future, please don’t hesitate to create a new forum topic. We’ll be more than happy to assist you again.
Thank you.