Adding SEO hreflang Tags


Thanks in advance for your assistance.

I have not spent a lot of time in the CMS side of the side versus Commerce and we need to add HREFLANG tags to all of our sites so that users will get the correct content when they browse and log in.

What is the easiest way to add these tags to the websites?

We are using Episerver CMS version 8.1

Jan 31, 2018 15:21

This topic provides an introduction to globalization and language management for version 8 Episerver platform:

Jan 31, 2018 17:56


Thanks for the reference, let me explain futher. The marketing company has given me several sets of tags each contain variations of the following on a page by page basis. They insist that these tags need to be added to the pages themselves. However epi uses a root masterpage and content templates. how would I add this set of tags to the aboutus page. 

<link rel="alternate" hreflang="x-default" href="" />
<link rel="alternate" hreflang="en-AU" href="" />
<link rel="alternate" hreflang="en-CA" href="" />

Thansk so much

Feb 20, 2018 17:45

There is a HtmlHelper available that will render out these tags for you based on what languages your pages are available in


This helper takes into account the page access rights / published status etc. It will show the href as the primary host name that you have bound to your site (following the ruiles in the documentation above). We put this call in our Layout page so it appears on any content page

N.B. These tags don't help customers be served the right language page, instead they help search engines index and understand language variants of a piece of content

Feb 20, 2018 18:36


Can this tag be used in a webforms implementation of Episerver??

In fact we are not concerned about the language being served, just the order of the search results.


Edited, Feb 20, 2018 19:10

There is a WebControl, but it looks like this feature was only added sometime in the Version 9 CMS release cycle.

The functionality isn't hard to replicate yourself. The below code will get you all available language variants from the current page, filtered by access rights, publish status etc.

var pageLanguagesBranches = contentRepository.GetLanguageBranches<PageData>(CurrentPage.ContentLink).ToList();
var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();

You'd just need to iterate through that data and calculate the correct host to produce markup as above.

Feb 20, 2018 22:03

Ok I am going to give this a try.


Feb 20, 2018 22:39

Hi there,

I am trying to use the suggested code snippet by Mark Erverad in my HtmlHelpers.cs:

I pasted it as if into the file, but Visual Studio showed up some errors. So far I have the following:

var pageLanguagesBranches = ContentRepository.GetLanguageBranches<PageData>(ICurrentPage.ContentLink).ToList();
var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();

Visual Studio is informing me that ICurrentPage does not contain a definition for ContentLink.

Any help would be really appreciated.

Apr 02, 2019 10:27

CurrentPage right? Not ICurrentPage. You should have that as a parameter in your controller.
Hreflang tags are good to have yes if you have many languages. It helps google to determine what version to display for the current user in the search result.

Edited, Apr 03, 2019 10:04

epiNew: It looks like you are trying the GetLanguageBranches method without obtaining an instance of IContentRepository.
If you are doing this in an extension method, you can inject IContentRepository in the static extension class like this:

private static readonly Injected<IContentRepository> _contentRepository = default(Injected<IContentRepository>);

Then rewrite line 1 of your code like this, assuming you pass in a PageData instance, called currentPage:

var pageLanguagesBranches = _contentRepository.Service.GetLanguageBranches<PageData>(currentPage.ContentLink).ToList();
Apr 03, 2019 10:23
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.