Changing the og:locale output

Last update: 10 August, 2017

When you enable OpenGraph in Yoast SEO, it'll output an og:locale meta tag. This og:locale is based on the language settings for your WordPress install. So if you want to have it output nl_NL instead of the default en_US, you simply switch your WordPress installs language to nl_NL. You can read how to do that on the WordPress codex.

If you don't want to change the language of your WordPress install but do want to change the locale output of Yoast SEO, you can do so by filtering the output. You should add code that looks like this to your theme's functions.php:

function yst_wpseo_change_og_locale( $locale ) {
return 'nl_NL';
}
add_filter( 'wpseo_locale', 'yst_wpseo_change_og_locale' );
TIP: OpenGraph has a limited list of supported og:locale designations. Learn more here.

How to Remove og:locale

If you would like to remove the og:locale you will need to unhook WPSE_OpenGraph->locale() from wpseo_opengraph by adding the code below to your functions.php file. This code snippet may work in most cases, however, does not work if you are using PHP 5.2 on your server. For the health and safety of your site, we recommend creating a backup of your site and database prior to any code changes as we are unable to guarantee exactly what would happen on your specific site.

add_action( 'template_redirect', function () {
    global $wpseo_og;

    if ( isset( $wpseo_og ) ) {
        remove_action( 'wpseo_opengraph', [ $wpseo_og, 'locale' ], 1 );
    }
}, 1000 );

Was this article helpful? ·