What this code do is looking for a custom field called “locale” that you can add to any posts to override the default one.

I choosed it_IT as default just for example but you can do it your own way.

If you’re not using the Genesis framework you need to implement yourself the genesis_get_custom_field function that retrieve the custom field value from the current post or page.

Extend the changes to other plugins

Filtering by hooking the wpseo_locale hook will only affect the Yoast plugin.

If you want to extends those changes to other plugins, for instance the Genesis builtin “eNews” plugin, you have to manipulate the return value of the get_locale() wordpress core function by hooking the locale hook.

You can do this by just replacing:

add_filter('wpseo_locale', 'my_wpseo_locale' );

with

add_filter('locale', 'my_wpseo_locale' );

HowTo Fix incorrect og:locale in Yoast's WordPress SEO Plugin with Genesis framework, 3.7 out of 5 based on 3 ratings