Typoscript language menu (with deeplinks)

Adding a language menu, even with 10 languages like in this example is pretty straightforward. Use stdWrap.typolink.addQueryString = 1 to make deeplinks, even for your own custom plugins.

# Language menu wth deeplinks
obj.langMenu = COA
obj.langMenu.wrap = <nav id="language-select"><ul> | </ul></nav>
obj.langMenu.10 = HMENU
obj.langMenu.10 {
	special=language
	special.value = 6,0,3,5,2,1,8,7,9,4
	1 = TMENU
	1 {
		wrap = |

		NO = 1
		NO {
			linkWrap = <li>|</li>
			stdWrap.override = Deutsch || English || Español || Français || Italiano || Nederlands || Svenska || עברית || العربية || 日本語 
			doNotLinkIt = 1
			stdWrap.typolink.parameter.data = page:uid
			stdWrap.typolink.additionalParams = &L=6 || &L=0 || &L=3 || &L=5 || &L=2 || &L=1 || &L=8 || &L=7 || &L=9 || &L=4
			stdWrap.typolink.addQueryString = 1
			stdWrap.typolink.addQueryString.exclude = L,id,cHash,no_cache,gclid,utm_source,utm_medium,utm_campaign
			stdWrap.typolink.addQueryString.method = GET
			stdWrap.typolink.useCacheHash = 1
			stdWrap.typolink.no_cache = 0
			stdWrap.typolink.ATagParams = hreflang="de" || hreflang="en" || hreflang="es" || hreflang="fr" || hreflang="it" || hreflang="nl" || hreflang="sv" || hreflang="ar" || hreflang="he" || hreflang="ja"
			stdWrap.typolink.ATagTitle = Deutsch || English || Español || Français || Italiano || Nederlands || Svenska || עברית || العربية || 日本語 
		}

		ACT < .NO
		ACT {
			linkWrap = <li class="active">|</li>
			stdWrap.typolink.ATagParams = class="active"
			doNotLinkIt = 1
		}


	}
}

Google isn’t satisfied with just the hreflang attribute on links in the example above. For your website to show the tags in the section International targeting in Google Webmaster Tools, you need to add alternate links tags to your <head> section.
The snippet below also uses the addQueryString, to make sure every page has unique hreflang links.

# SEO alternate hreflang links in header
headerData.22 = HMENU
headerData.22 {
	special = language
	special.value = 6,0,3,5,2,1,8,7,9,4
	1 = TMENU
	1 {
		NO = 1
		NO {
			stdWrap.cObject = TEXT
			stdWrap.cObject {
				value = de || en || es || fr || it || nl || sv || he || ar || ja
			}
			linkWrap = <link rel="alternate" hreflang="|
			doNotLinkIt = 1
			after.cObject = TEXT
			after.cObject {
				stdWrap.wrap = " href="|" />
				stdWrap.typolink.parameter.data = page:uid
				stdWrap.typolink.additionalParams = &L=6 || &L=0 || &L=3 || &L=5 || &L=2 || &L=1 || &L=8 || &L=7 || &L=9 || &L=4

				stdWrap.typolink.addQueryString = 1
				stdWrap.typolink.addQueryString.exclude = L,id,cHash,no_cache,gclid,utm_source,utm_medium,utm_campaign
				stdWrap.typolink.addQueryString.method = GET
				stdWrap.typolink.useCacheHash = 1
				stdWrap.typolink.no_cache = 0
				stdWrap.typolink.returnLast = url
			}
		}
	}
}

Leave a Reply