adding rel="alternate" hreflang tag for alternate languages

peter kuhn asked on March 6, 2014 09:30

Hi all,

We are launching a new UK specific culture for my company's Kentico powered site. As it will have primarily duplicate content, I need to implement rel="alternate" hreflang tags in my Head on all pages - similar to Bacardi has (they are on Kentico as well). Here's their output on a particular page:

<link rel="alternate" href="//www.bacardi.com/au/Cocktails/featured" hreflang="en-au" />
<link rel="alternate" href="//www.bacardi.com/in/Cocktails/featured" hreflang="en-gb" />
<link rel="alternate" href="//www.bacardi.com/uk/Cocktails/featured" hreflang="en-gb" />
<link rel="alternate" href="//www.bacardi.com/us/Cocktails/featured" hreflang="en-us" />

I can see that it is clearly possible - but I don't know enough on how to implement it. Any assistance would be terrific. Thank you!

pete

Correct Answer

Brenden Kehren answered on March 7, 2014 16:17

Ok as I read it again, I see they have to be unique for each page is that correct? If so, you could use a macro in the master page.

<link rel="alternate" href="//www.bacardi.com/au/a{% CMSContext.CurrentDocument.NodeAliasPath |(identity)GlobalAdministrator%}" hreflang="en-au" />

The NodeAliasPath will return the URL friendly path for the requested page.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on March 7, 2014 14:29

Hi,

You can add these tags to the master page directly - on the root document switch to Masterpage tab and add the data into the header section. This will be shared for all documents. Another way is to use the "Head HTML" web part - either on the master page template or on the individual page templates and add the header tags here. You can also use macros for dynamic content of this web part. And another way would be to modify the PortalTemplate.aspx file (I assume that you are using portal engine templates) and modify the header tags in the code here.

Best regards,
Juraj Ondrus

0 votesVote for this answer Mark as a Correct answer

peter kuhn answered on March 7, 2014 14:52

Hi Juraj,

Thanks for the info. I guess my main question - as we have a couple hundred pages - is there a way to do this systematically? Or does it have to be a manual effort?

pete

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 7, 2014 16:14

If you do it to your master page, the child pages that inherit the master page will automatically have those links on them simply by placing it on that one page.

0 votesVote for this answer Mark as a Correct answer

peter kuhn answered on March 10, 2014 11:41

Thank you Brenden! That's exactly what I was looking for. Will post back with my results.

0 votesVote for this answer Mark as a Correct answer

peter kuhn answered on March 11, 2014 10:17 (last edited on December 10, 2019 02:30)

One more request on this.. so far is is working great!

The only issue - my homepage document alias is "Home", so the rel tag is printing out as:

Ideally that should be written as (withough "Home")

I'm still quite new to all of this - but have found this macro - can I use it to write a static value for the Homepage (to exclude the Home alias), and then use the dynamic macro for all other pages? {%CMSContext.CurrentDocument.NodeAliasPath|(notequals)/Home|(identity)GlobalAdministrator%}

It don't quite understand the K# syntax. What I want is (please forgive the crazy pseudocode! ) :

if (NodeAliasPath = "Home") { print // removes "Home" for this one page } else //print the regular macro version { print }

0 votesVote for this answer Mark as a Correct answer

peter kuhn answered on March 11, 2014 10:20 (last edited on December 10, 2019 02:30)

oops... my formatting went missing! basically i want this:

<link rel="alternate" href="//www.ipswitchft.co.uk{% CMSContext.CurrentDocument.NodeAliasPath |(identity)GlobalAdministrator%}" hreflang="en-gb" />

on every page that is NOT the homepage. on the homepage, i want

<link rel="alternate" href="//www.ipswitchft.co.uk/" hreflang="en-gb" />

as the first version writes "/Home".

0 votesVote for this answer Mark as a Correct answer

peter kuhn answered on March 13, 2014 12:51

Ended up going with this

which gets around the /Home issue.

0 votesVote for this answer Mark as a Correct answer

peter kuhn answered on March 13, 2014 12:52

sheesh - sorry - this!

    <link rel="alternate" href="//www.ipswitchft.co.uk{%currenturl%}" hreflang="en-gb" />
0 votesVote for this answer Mark as a Correct answer

Alen Jose answered on October 28, 2014 12:32

How can we do if the url is dynamic with lot of language code? eg: www.google.com/uk/blahblah... hreflang="en" www.google.com/nl/blahblah... hreflang="nl" www.google.com/be/blahblah... hreflang="be" www.google.com/fr/blahblah... hreflang="fr"

0 votesVote for this answer Mark as a Correct answer

Sandro Jankovic answered on December 2, 2014 12:34

Hi Alen,

I am not sure that I understand the issue - how is the URL being generated and why wouldn't you be able to use macros or K# as explained? Please let me know if you have any additional details that would help us better understand the issue.

Thanks!

Best Regards,

Sandro

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.