Try our conversational search powered by Generative AI!

Adding SEO hreflang Tags

jim
jim
Vote:
 

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

#187682
Jan 31, 2018 15:21
Vote:
 

Jim,
This topic provides an introduction to globalization and language management for version 8 Episerver platform: https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/8/Globalization/Globalization/

#187685
Jan 31, 2018 17:56
jim
Vote:
 

Jim

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="https://www.blah.com/about-us/" />
<link rel="alternate" hreflang="en-AU" href="https://www.blah.com.au/about-us/" />
<link rel="alternate" hreflang="en-CA" href="https://www.blah.ca/about-us/" />

Thansk so much

#188355
Feb 20, 2018 17:45
Vote:
 

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

  @Html.AlternateLinks()

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

#188357
Feb 20, 2018 18:36
jim
Vote:
 

Mark

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.

Thanks

#188358
Edited, Feb 20, 2018 19:10
Vote:
 

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

https://world.episerver.com/documentation/Class-library/?documentId=cms/9/AFB0A735

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.

#188359
Feb 20, 2018 22:03
jim
Vote:
 

Ok I am going to give this a try.

Thanks

#188360
Feb 20, 2018 22:39
Vote:
 

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.

#202835
Apr 02, 2019 10:27
Vote:
 

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.

#202888
Edited, Apr 03, 2019 10:03
Vote:
 

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();
#202893
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.