Change locale in WordPress SEO to EN_GB

A client this morning emailed me to ask how to change the locale of her website from the default en_US language to the UK version while running the Yoast WordPress SEO plugin.

While some people think that by installing WordPress as the UK version does this, it doesn’t. This only really alters the language file used in the admin dashboard areas and changes words like ‘Trash’ to ‘Bin’, the UK equivalent. Personally, I haven’t ever felt the need to change this as I’m quite used to working with th US version now, but I know some people would probably still do this.

Changing the locale is a little different though. This appears in the source of the webpages and is default to this:

<meta property="og:locale" content="en_US" />
[divider line_type=”No Line” custom_height=”10″]
This is actually generated by the Yoast WordPress SEO plugin.

To change this, a few lines of code will get this permanently changed for you:

add_filter('wpseo_locale', 'override_og_locale');
function override_og_locale($locale)
{
return "en_GB";
}

[divider line_type=”No Line” custom_height=”10″]
By adding in this snippet to the theme functionsphp file, we can force the Yoast plugin to output the en_GB format, allowing it to be changed correctly in the source of the page.

<meta property="og:locale" content="en_GB" />
[divider line_type=”No Line” custom_height=”20″]

Prefer A Plugin?

If you are not comfortable editing your theme files OR if you regularly update your theme and don’t want to keep transferring code from the old to new, you can install my plugin. I use this plugin on my own site too. Grab a copy of it below for free.

Just install and activate – no settings

[ddownload id=”1434″]

Useful post? Share it

5 comments on “Change locale in WordPress SEO to EN_GB

  1. Do I delete all 5 lines and replace it with the one line snippet?

    Also, is the plugin available directly via wordpress so I can install without ftp access?

    Cheers

    1. No, you just need to add the 5 lines into your functions.php file. No need to delete any existing code.

      As for the plugin, you can upload the zip file directly into the backend of WordPress, under the ‘Add Plugin’ section. 🙂

  2. Hello, I tried with the code and the plugin; however this change does not force the Yoast plugin to force the output format es_PE

    1. Oh, I see it too. It seems the Yoast plugin may not support that language and code combo, it reverted to ‘es_ES’ for me too. Guess Yoast aren’t supporting this variant just yet.

  3. Thanks so much for your help on this. I am using a very complex theme and I’m unable to find the theme functionsphp file within WP itself. Even using Aptana, the debs have made it impossible to root around in the back end, that I had to give up. So I installed your plugin as a zip file, activated and ta-da. Nothing. It hasn’t worked. Never mind. Thank you for your brilliant post though 🙂

Leave a Reply

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