-
Hello,
The company I work for just launched a site in Swahili. Turns out that WordPress sets the lang attribute correctly to “sw” in the html tag, but RankMath sets the OpenGraph locale to “sw_KE for Kenya.
<meta property="og:locale" content="sw_KE" />
The problem is that a few more countries speak the language and we need to target them all, not just Kenya.
From what I read in the OpenGraph docs we need to use og:locale:alternate for the others.I found some code for Polylang compatibility on GitHub, changed it a bit and put it in the theme’s functions.php
function alt_rankmath_locales() { $og = new RankMath\OpenGraph\OpenGraph(); $og->network = 'facebook'; $languages = array('sw_UG', 'sw_CD', 'sw_TZ'); foreach ( $languages as $lang ) { $og->tag('og:locale:alternate', $lang ); } } add_filter( 'rank_math/opengraph/facebook', 'alt_rankmath_locales', 10 );
The code above works as expected and adds the folloing extra tags
<meta property="og:locale:alternate" content="sw_UG" /> <meta property="og:locale:alternate" content="sw_CD" /> <meta property="og:locale:alternate" content="sw_TZ" />
but it would be better if you could add 2 more options in the settings:
1) A way to set the main locale if WordPress is in a language, spoken in multiple countries.
For example with Swahili – someone might be targeting only Uganda and doesn’t care about Kenya
2) An option to choose the alternative OpenGraph locales if WordPress is using such a language. This is applicable even for English – someone might be interested in both USA and Canada and launching separate sites for them sounds impractical, especially if the content will be the same.
The ticket ‘Alternative OpenGraph Locales’ is closed to new replies.