<p>If you're looking to get the locale code for each site's language globally, it'd be something like this:</p>

<pre><code>{% for locale in craft.i18n.getSiteLocales() %}
    {{ locale }}
{% endfor %}
</code></pre>

<p>If you're in the context of an entry, and you want to get the full URL and locale code for each site that entry is enabled it, it'd be similar to the answer here: <a href="https://craftcms.stackexchange.com/a/23751/57">https://craftcms.stackexchange.com/a/23751/57</a></p>

<pre><code>{# Grab the entry #}
{% set entry = craft.entries.id(2).one() %}

{# loop through all of the supported sites for the entry #}
{% for siteInGroup in entry.getSupportedSites() %}
    {% set site = craft.app.sites.getSiteById(siteInGroup['siteId']) %}

    {# Grab the entry for the given site #}
    {% set entryForSite = craft.entries.id(entry.id).siteId(site.id).one() %}

    {# output the site-specific entry info #}
    &lt;link rel="alternate" href="{{ entryForSite.url }}" hreflang="{{ site.language }}"&gt;{{ entryForSite.title }}&lt;/link&gt;
{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-08-28T08:58:55.720Z
Hi Brad - many thanks for your reply.  But unfortunately, that only generates the 'homepage' url for each site.  The link rel="alternate" mark-up needs to output the alternative URL for each individual page of the site.  I hope that makes sense?
MGX
CC BY-SA 4.0
2018-08-28T23:30:37.770Z
Sorry, I don't think I'm following... can you update the original question with some specific examples of what you're looking for?
Brad Bell
CC BY-SA 4.0
2018-08-29T07:43:31.320Z
Hi Brad - many thanks for your reply.  This Google Search Console give the best explanation of what's required: https://support.google.com/webmasters/answer/189077?hl=en
So with regard to a Craft site, for each individual page of the site we need to be able to output the link rel="alternate" mark-up that shows the full URL for each language version, together with the respective hreflang value.  This might be something like:
MGX
CC BY-SA 4.0
2018-08-29T07:51:42.387Z
Hi Brad - many thanks for your reply.  This Google Search Console give the best explanation of what's required: https://support.google.com/webmasters/answer/189077?hl=en
So with regard to a Craft site, for each individual page of the site we need to be able to output the link rel="alternate" mark-up that shows the full URL for each language version, together with the respective 'hreflang' value.  So each page has a unique set of mark-up for this in the head.
But...the code you posted earlier just outputs the homepage of each language variation.
I hope that makes sense?
Thanks!
MGX
CC BY-SA 4.0
2018-08-24T22:35:08.697Z
2018-08-24T22:35:08.697Z
Brad Bell
<p>I can't work out how to output <code>&lt;link rel="alternate"&gt;</code> for each language variation? </p>

<p>Is there any easy way to do this please?</p>

<p>Many thanks!</p>

CC BY-SA 4.0
2018-08-17T10:10:35.633Z
Is this with Craft 3's translation features?
Jay
CC BY-SA 4.0
2018-08-17T18:07:02.260Z
Craft 2 or Craft 3?
Brad Bell
CC BY-SA 4.0
2018-09-23T23:33:43.067Z
If you use [SEOmatic](https://github.com/nystudio107/craft-seomatic), this is something it does for you automatically, FWIW.
andrew.welch
<language>
How to output <link rel="alternate"> for each language?
# How to output <link rel="alternate"> for each language?

(Asked by: username_0 on 2018-08-17)

I can't work out how to output  for each language variation?

Is there any easy way to do this please?

Many thanks!

**Tags:** language

> **Comments:**
> **username_1**: Is this with Craft 3's translation features?  
> **username_2**: Craft 2 or Craft 3?  
> **username_3**: If you use [SEOmatic](https://github.com/nystudio107/craft-seomatic), this is something it does for you automatically, FWIW.  

---

## 1 answers

### Answer by username_2 on 2018-08-24. Score: 0

If you're looking to get the locale code for each site's language globally, it'd be something like this:
{% for locale in craft.i18n.getSiteLocales() %}
    {{ locale }}
{% endfor %}

If you're in the context of an entry, and you want to get the full URL and locale code for each site that entry is enabled it, it'd be similar to the answer here: https://craftcms.stackexchange.com/a/23751/57
{# Grab the entry #}
{% set entry = craft.entries.id(2).one() %}

{# loop through all of the supported sites for the entry #}
{% for siteInGroup in entry.getSupportedSites() %}
    {% set site = craft.app.sites.getSiteById(siteInGroup['siteId']) %}

    {# Grab the entry for the given site #}
    {% set entryForSite = craft.entries.id(entry.id).siteId(site.id).one() %}

    {# output the site-specific entry info #}
    {{ entryForSite.title }}
{% endfor %}

> **Comments:**
> **username_0**: Hi Brad - many thanks for your reply.  But unfortunately, that only generates the 'homepage' url for each site.  The link rel="alternate" mark-up needs to output the alternative URL for each individual page of the site.  I hope that makes sense?  
> **username_2**: Sorry, I don't think I'm following... can you update the original question with some specific examples of what you're looking for?  
> **username_0**: Hi Brad - many thanks for your reply.  This Google Search Console give the best explanation of what's required: https://support.google.com/webmasters/answer/189077?hl=en So with regard to a Craft site, for each individual page of the site we need to be able to output the link rel="alternate" mark-up that shows the full URL for each language version, together with the respective hreflang value.  This might be something like:  
> **username_0**: Hi Brad - many thanks for your reply.  This Google Search Console give the best explanation of what's required: https://support.google.com/webmasters/answer/189077?hl=en So with regard to a Craft site, for each individual page of the site we need to be able to output the link rel="alternate" mark-up that shows the full URL for each language version, together with the respective 'hreflang' value.  So each page has a unique set of mark-up for this in the head. But...the code you posted earlier just outputs the homepage of each language variation. I hope that makes sense? Thanks!  

---

