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!

2 thoughts on “Generate hreflang alternate tags in TYPO3”

  1. Full TS
    page {
    headerData {
    5112 = HMENU
    5112 {
    special = language
    special.value = 0,1,1,1
    1 = TMENU
    1 {
    NO = 1
    NO {
    wrapItemAndSub =
    doNotLinkIt = 1
    stdWrap {
    cObject = COA
    cObject {

    10 = TEXT
    10 {
    noTrimWrap = | href=”|” |
    typolink.parameter.data = page:uid
    typolink.additionalParams = &L=0 || &L=1 || &L=1 || &L=1
    typolink.returnLast = url
    typolink.forceAbsoluteUrl = 1
    }
    20 = TEXT
    20 {
    noTrimWrap = |hreflang=”|” |
    value = de || en-us || en-gb || en
    }
    }
    }
    USERDEF1
    stdWrap >
    }
    USERDEF2 < .USERDEF1
    }
    }
    }
    }
    }

Leave a Comment

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.

Scroll to Top