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″]