Change language tags in sitemap.xml

Hi,

I’m running into a problem with my site and the language tags that the sitemap.xml get added to it. I have a website that aims to the European market, we have two language versions. The first version is dutch and the second is English.

The sitemap shows the following for my home page:
<x:link rel=“alternate” hreflang=“en-gb” href=“https://domain.nl/en” />
<x:link rel=“alternate” hreflang=“nl-nl” href=“https://domain.nl/nl” />

However, what I would like to have is, hreflang=“nl” for the /nl version and hreflang=“x-default” for the /en version because this one is for every language and country across Europe.
We are currently working on a german specified version, but that one should also show up in countries that speak german instead of only germany.

I’ve tried to edit the language and country tags in the dashboard / multilingual / setup
But when I leave the country blank I get an error that a country should be selected.

Does anyone know how to alter the language tags, so the sitemap.xml is displayed correctly?

Are you using version 9? In this specific case the work around is you can manually update the sitemap to reflect the default language

Not what i was expecting but a great idea it is.
and it got me thinking a little more so,
I’ve made a PHP script and saved it as sitemap.php with the following contents:

<?php
$xml = file_get_contents("sitemap.xml");
$xml = str_replace('hreflang="en-gb"', 'hreflang="x-default"', $xml);
    $xml = str_replace('hreflang="nl-nl"', 'hreflang="nl"', $xml);
  echo $xml;  
?>

I’ve told Google search console that my sitemap is sitemap.php instead of sitemap.xml and it appears to be working!

1 Like