<p>Have you tried using <code>{{ craft.entries.id(entry.id).locale(locale.id).first().url }}</code> inside the for loop you have made?</p>

CC BY-SA 3.0
2017-03-30T08:07:16.863Z
Great, glad it sorted it for you, see you at the next craft meet up :P
Matt Shearing
CC BY-SA 3.0
2017-03-29T15:49:49.640Z
2017-03-29T15:49:49.640Z
Matt Shearing
<p>Just adding hreflang tags to the head on all pages of my multi-locale site...</p>

<pre><code>{% for locale in craft.i18n.getSiteLocales() %}
    &lt;link rel="alternate" href="{{ entry.url }}" hreflang="{{ locale }}"&gt;
{% endfor %}
</code></pre>

<p>Nearly there, but obviously this outputs my list of locales with the entry url for the <em>current locale</em> only. What I need is to output the entry url for <em>each locale</em>. Anyone done this before?</p>

CC BY-SA 3.0
2017-04-28T15:27:34.520Z
The accepted answer works - however, beware that the `hreflang` attribute should not necessarily be the same format as Craft's `locale` values. Depending on your locales, you may need to translate them into their ISO equivalents for language and country. For example `en_ca` would become `en-CA`.
James Smith
<localization>
Output Locale URLs in hreflang
# Output Locale URLs in hreflang

(Asked by: username_0 on 2017-03-29)

Just adding hreflang tags to the head on all pages of my multi-locale site...
{% for locale in craft.i18n.getSiteLocales() %}
    
{% endfor %}

Nearly there, but obviously this outputs my list of locales with the entry url for the current locale only. What I need is to output the entry url for each locale. Anyone done this before?

**Tags:** localization
> **Comments:**
> **username_1**: The accepted answer works - however, beware that the `hreflang` attribute should not necessarily be the same format as Craft's `locale` values. Depending on your locales, you may need to translate them into their ISO equivalents for language and country. For example `en_ca` would become `en-CA`.  

---

## 1 answers

### Answer by username_2 on 2017-03-29. Score: 2 | Accepted answer

Have you tried using `{{ craft.entries.id(entry.id).locale(locale.id).first().url }}` inside the for loop you have made?

> **Comments:**
> **username_2**: Great, glad it sorted it for you, see you at the next craft meet up :P  

---

