Link rel='alternate' tags hreflang does not include language and locale
mbs-arran-baker opened this issue · comments
When meta alternate links are generated {{ site:short_locale }} is used which causes duplicate hreflang's on multisites that have two locales with the same language.
For a site with en-gb and en-us;
{{ if alternate_locales }}
<link rel="alternate" href="{{ canonical_url }}" hreflang="{{ site:short_locale }}" />
{{ alternate_locales }}
<link rel="alternate" href="{{ url }}" hreflang="{{ site:short_locale }}" />
{{ /alternate_locales }}
{{ /if }}
produces:
<link rel="alternate" href="https://site.test/" hreflang="en" />
<link rel="alternate" href="https://site.test/us" hreflang="en" />
Ideal hreflang to include both language and locale:
<link rel="alternate" href="https://site.test/" hreflang="en-gb" />
<link rel="alternate" href="https://site.test/us" hreflang="en-us" />
What url are you on when you see this output? And can you provide your sites.php config file?
This is happening on every url that is published on both en-gb and en-us locales
'sites' => [
'default' => [
'name' => 'website UK',
'locale' => 'en-gb',
'url' => '/',
'attributes' => [
'title' => 'English GB',
'title_short' => 'UK'
]
],
'us' => [
'name' => 'website US',
'locale' => 'en-us',
'url' => '/us/',
'attributes' => [
'title' => 'English US',
'title_short' => 'US'
]
],
'german' => [
'name' => 'website DE',
'locale' => 'de-de',
'url' => '/de/',
'attributes' => [
'title' => 'Deutsch',
'title_short' => 'DE'
]
],
'italian' => [
'name' => 'website IT',
'locale' => 'it-it',
'url' => '/it/',
'attributes' => [
'title' => 'Italiano',
'title_short' => 'IT'
]
],
'spanish' => [
'name' => 'website ES',
'locale' => 'es-es',
'url' => '/es/',
'attributes' => [
'title' => 'Español',
'title_short' => 'ES'
]
],
'french' => [
'name' => 'website FR',
'locale' => 'fr-fr',
'url' => '/fr/',
'attributes' => [
'title' => 'Français',
'title_short' => 'FR'
]
],
],
So on a British URL you also see this?
<link rel="alternate" href="https://site.test/" hreflang="en" />
<link rel="alternate" href="https://site.test/us" hreflang="en" />
Yes - on an any url that is an 'en' language url and that has two entries published with an 'en' language prefix. So on en-gb and en-us they both show:
<link rel="alternate" href="https://site.test/" hreflang="en" />
<link rel="alternate" href="https://site.test/us" hreflang="en" />
We have pulled through the {{ site:locale }} variable for the hreflang instead, but the seo-pro package uses the {{ site:short_locale }} variable which changes both 'en-gb' and 'en-us' to just 'en'.
Has there been a fix for this? I am getting the same as above, the local defaults to 'en'
Has there been a fix for this? I am getting the same as above, the local defaults to 'en'
The issue is still open so the issue is yet to be fixed.
Tagged fix in 5.4.3 👍