Setting alternate hreflang in WordPress

UPDATE 2013-05-03:
After writing this I found out my approach was incorrect. I have since removed the code as it was not useful.
Dan’s team was kind enough to point me to Virgin Australia‘s site. If you inspect the source and search for hreflang, you’ll see how it should be done.
/UPDATE
After seeing the excellent talk by Dan Petrovic at the Melbourne WordCamp, I went to find out more about the <link rel=”alternate” hreflang=”en-AU” href=”http://somesite.com.au/” />. He has an article describing it. Essentially if you have multiple sites that have similar content (but not exactly the same) then you can instruct google that the sites serve different regions by using the rel=alternate hreflang=”en=gb” options for the link tag.
A common scenario that you might find this useful would be in online stores where there is a different store for each country.
eg. for site somesite.com.au you want a <link> tag like this:
<link rel=”alternate” hreflang=”en-AU” href=”http://somesite.com.au/” />
and for somesite.com you might want a tag like this:
<link rel=”alternate” hreflang=”en-US” href=”http://somesite.com/” />
and you want to remove the rel=”canonical” option too.
I couldn’t find a plugin that would implement this in WordPress so I wrote one and put it up on github. Yoast does not have an option for this as far as I can tell.
At some point I might put it up on wordpress.org too if it seems like there is interest in it.


Comments

10 responses to “Setting alternate hreflang in WordPress”

  1. I’ve been looking for plugin to help me implement rel=”alternate” hreflang markup. May i ask what was incorrect with your plugins, your description sounds about correct? Any plan to put ti back up in corrected?

  2. Jason Lewis Avatar
    Jason Lewis

    Initially I thought you just needed one rel=”alternate” hreflang for the whole site. but in fact you need hreflang entries on each page, pointing to all the relevant pages for other languages. Compare the source for the following two pages (search for hreflang):
    https://www.virginaustralia.com/au/en/
    https://www.virginaustralia.com/nz/en/

  3. Any plans to re engineer the plugin so it works correctly?

    1. Jason Lewis Avatar
      Jason Lewis

      Not at this time no.

    2. Jason Lewis Avatar
      Jason Lewis

      No

  4. That’s a shame. I’m currently looking at a way of adding rel=”alternate using custom fields. Never coded wordpress before, nor am i a coder, so its a nice learning curve! Getting there though.

  5. Hi jason,
    Did you ever find a solution to this or do you know of any plugins that do it?
    Thanks,
    Ian

  6. Jason Lewis Avatar
    Jason Lewis

    Hi Ian,
    No, sorry. It’s non trivial.

  7. I use Add Meta Tags plugin to fill in the hreflang entries per post. Since I use Yoast, I don’t use the description and title offered by Add Meta Tags, just their Full Meta Tags field for entering hreflang entries

  8. Try this wordpress plugin: https://wordpress.org/plugins/language-selector-related/
    I just installed it minutes ago, so can’t confirm but looks like just what i need. (I have 2 blog, each with the same content but with different language and on different domain.)

Leave a Reply

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