Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T08:58:55.720Z
Answers.Text: 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?
Answers.UserDisplayName: MGX
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T23:30:37.770Z
Answers.Text: Sorry, I don't think I'm following... can you update the original question with some specific examples of what you're looking for?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T07:43:31.320Z
Answers.Text: 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:
Answers.UserDisplayName: MGX
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T07:51:42.387Z
Answers.Text: 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!
Answers.UserDisplayName: MGX
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T22:35:08.697Z
Answers.LastActivityDate: 2018-08-24T22:35:08.697Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-17T10:10:35.633Z
Comments.Text: Is this with Craft 3's translation features?
Comments.UserDisplayName: Jay
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-17T18:07:02.260Z
Comments.Text: Craft 2 or Craft 3?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-23T23:33:43.067Z
Comments.Text: If you use [SEOmatic](https://github.com/nystudio107/craft-seomatic), this is something it does for you automatically, FWIW.
Comments.UserDisplayName: andrew.welch
Tags: <language>
Title: How to output <link rel="alternate"> for each language?
ThreadText: # 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 `<link rel="alternate">` 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 #}
      <link rel="alternate" href="{{ entryForSite.url }}" hreflang="{{ site.language }}">{{ entryForSite.title }}</link>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Hi username_2 - 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 username_2 - 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 username_2 - 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!  
  
  ---
  
  