Generate hreflang alternate tags in TYPO3

Here is a quick TypoScript snippet that generates hreflang alternate tags in TYPO3. Take note of the following parameters:

  • special.value: set IDs of languages available, e.g. 0
  • stdWrap.cObject.value: specify the locale corresponding to special.value, e.g. de-AT
  • stdWrap.typolink.additionalParams: specify the special.value values for each locale set

TypoScript code to generate hreflang alternate tags

Here’s the snippet for a couple of exemplary locales:

page.headerData.100 = HMENU
page.headerData.100 {
  special = language
  special.value = 0,1,2,3,4
  1 = TMENU
  1 {
    NO = 1
    NO {
      stdWrap.cObject = TEXT
      stdWrap.cObject {
        value = de-AT || en || it-IT || fr-FR || sl-SI
      }
      linkWrap = 
        stdWrap.typolink.parameter.data = page:uid
        stdWrap.typolink.additionalParams = &L=0 || &L=1 || &L=2 || &L=3 || &L=4
        stdWrap.typolink.returnLast = url
      }
    }
  }
}

Snippet Output

The snippet above produces the following output:

<link rel="alternate" hreflang="de-AT" href="http://www.somedomain.at/at-page" />
<link rel="alternate" hreflang="en" href="http://www.somedomain.com/en-page" /> 
<link rel="alternate" hreflang="it-IT" href="http://www.somedomain.it/it-page" /> 
<link rel="alternate" hreflang="fr-FR" href="http://www.somedomain.fr/fr-page" /> 
<link rel="alternate" hreflang="sl-SI" href="http://www.somedomain.si/si-page" />

That’s it!

You may also like...

1 Response

  1. Nice one! 🙂 cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.