Yoast SEO OpenGraph Tags: Change the og:locale output
When you enable OpenGraph settings 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 it to output nl_NL
instead of the default en_US
, you simply switch your WordPress installs' language to nl_NL
. You can read more about that on the Make WordPress polyglots page.
Change the og:locale
tag
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
:
/**
* Changes the locale output.
*
* @param string $locale The current locale.
*
* @return string The locale.
*/
function yst_wpseo_change_og_locale( $locale ) {
return 'nl_NL';
}
add_filter( 'wpseo_locale', 'yst_wpseo_change_og_locale' );
Remove the og:locale
tag
If you would like to remove the og:locale
you will need to unhook WPSEO_OpenGraph->locale()
from wpseo_opengraph
by adding the code below to your theme's functions.php
file.
This code snippet works in most cases, however, it 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.
function remove_locale_presenter( $presenters ) {
return array_map( function( $presenter ) {
if ( ! $presenter instanceof Yoast\WP\SEO\Presenters\Open_Graph\Locale_Presenter ) {
return $presenter;
}
}, $presenters );
}
add_action( 'wpseo_frontend_presenters', 'remove_locale_presenter' );