Magento 1.9 – Add hreflang tags via XML custom layout panel in admin

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

Useful? Please buy me a beer.




Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *