Here is a quick, albeit very hacky solution to allow you to add hreflang tags to a page or item via the XML custom layout box in the admin.
It is possible to an hreflang tag using the action method=”addLinkRel” function. The issue is that one thinks one should be able to do this
<reference name="head"> <action method="addLinkRel"> <rel>alternate</rel> <hreflang>en-us</hreflang> <href>https://www.someotherurl.com</href> </action> </reference>
But this just gives you
<link rel="alternate" href="en-us" />
You can work around this by adding in some (hacky) additional quotes to the rel parameter like so:
<reference name="head"> <action method="addLinkRel"> <rel>alternate" hreflang="en-us</rel> <href>https://www.someotherurl.com/</href> </action> </reference>
This is rather horrid but you do end up with the desired result on the front end of
<link rel="alternate" hreflang="en-us" href="https://www.someotherurl.com/" />
Don’t forget that every hreflang tag pointing somewhere MUST have an hreflang tag pointing back to it from the other location. For many languages and sites this can get confusing so check you haven’t missed any by using an online hreflang checker.
I recommend either of these free tools
- flang from Dejan Tools – has a great simple interface but you need to check one URL at a time.
- or the Sistrix hreflang validator – this shows all hreflang links and all return links found.
Useful? Please buy me a beer.