statamic / seo-pro

An all-in-one site reporting, metadata wrangling, Open Graph managing, Twitter card making, sitemap generating, turn-key addon for Statamic.
https://statamic.com/addons/statamic/seo-pro
52 stars 33 forks source link

Link rel='alternate' tags hreflang does not include language and locale #296

Closed mbs-arran-baker closed 2 months ago

mbs-arran-baker commented 8 months ago

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" />
jasonvarga commented 8 months ago

What url are you on when you see this output? And can you provide your sites.php config file?

mbs-arran-baker commented 8 months ago

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'
            ]
        ],
    ],
jasonvarga commented 8 months ago

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" />
mbs-arran-baker commented 8 months ago

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'.

sattyframework commented 2 months ago

Has there been a fix for this? I am getting the same as above, the local defaults to 'en'

duncanmcclean commented 2 months ago

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.

jesseleite commented 2 months ago

Tagged fix in 5.4.3 👍