Go to main content

Get urls of a page's culture versions in Kentico

For SEO reasons you may need to generate alternate link tags with the hreflang attribute in your html output. In this quick tip I will show you a macro expression which generates these links for you in Kentico.

Get urls of a page's culture versions in Kentico

The macro simply goes through culture versions of the current page but for many people it is not obvious how to achieve that. Before you use the macro make sure you place following key into your web.config: <add key="CMSCheckPermissionsForDocumentCollection" value="false"/>. The reason for this is that developers of Kentico do not want to allow public user see documents collections via macro. This kind of security checks was present only in certain number of hotfixes in version 7 and 8. For more info go here: http://devnet.kentico.com/articles/page-macro-expressions-security

{% foreach (page in CurrentDocument.CultureVersions) {
  if (page.DocumentCulture != CurrentDocument.DocumentCulture) {
    "<link rel=\"alternate\" href=\""+ page.AbsoluteUrl + "\" hreflang=\""+ page.DocumentCulture +"\" />"
  }
}
#%}
Milan Lund

is a freelance web developer and a proud Basenji owner. His specialties are Kentico CMS/EMS and Kentico Cloud.

Further reading

all posts
  • Front-end & JavaScript

    Get visitor's country code in Node.js on Azure

    In this article I will provide you with a code snippet that gives you visitor's country code from a website running in the Node.js environment on Microsoft Azure.

  • Other

    Hotel Anybody: Od vize k technické realizaci

    Když jsem poprvé mluvil s Adamem Vodičkou o jeho vizích a o tom, jak by měl hotel Anybody fungovat, říkal jsem si: „Ty vole, to je ujetý“. Adam prohlásil: „Budeme fungovat bez rece…

  • Kentico CMS & EMS

    How do we teach university students to use Kentico

    From time to time a Kentico partner ask me if I could relocate myself permanently and work for them full time. Unfortunately, I can’t do that because I am a freelancer and I am loy…