Alternative OpenGraph Locales

#902510
  • Resolved Kevinmann
    Rank Math free

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    We apologize for the issue you are facing with the OpenGraph locale settings in Rank Math. Thank you for raising this concern and providing detailed information about your implementation.

    Currently, Rank Math automatically sets the og:locale tag based on the language selected in the WordPress General Settings. As you mentioned, it defaults to sw_KE for Swahili, which may not be ideal for all users targeting different countries that speak the same language.

    Your approach to add alternate locales using a custom function in the functions.php file is a great solution. This allows you to specify additional locales like sw_UG, sw_CD, and sw_TZ as needed.

    Regarding your suggestions:

    1. Setting the Main Locale: We understand that having the ability to set a primary locale for languages spoken in multiple countries would be beneficial. This feature could help users target specific regions more effectively.
    2. Choosing Alternative OpenGraph Locales: The option to select alternative locales for languages would indeed enhance flexibility, especially for widely spoken languages like English.

    We appreciate your feedback and will take it into consideration for future updates. In the meantime, if you have any further questions or need assistance, please feel free to reply to this ticket, and a human agent from the Rank Math Support team will assist you further.

    Thank you for your understanding!

    Sources:
    Open Graph Meta Tags » Rank Math

    Kevinmann
    Rank Math free

    Just a follow-up – the bot replied pretty well, but I still need a human to see my suggestions and forward them to the dev team in case they’re deemed useful.

    Hello,

    Thank you so much for getting in touch.

    1. You can make use of the filter code to change the primary og:locale our plugin generates. Here’s an example usage of our filter code:

    add_filter( "rank_math/opengraph/facebook/og_locale", function($content){
    	$content = 'sw_UG';
    	return $content;
    });

    2. At the moment, our plugin is letting other multi-language plugins such as TranslatePress and WPML handle the language versions in the tag which is why our plugin doesn’t have options to manipulate them.

    With that said, if this is something we can add in the future update, we will surely let you know. Thank you so much for your suggestion in the meantime.

    Hope that helps.

    Kevinmann
    Rank Math free

    Hello,

    Thank you for the filters tip, but what I’m proposing is exactly for the use cases where there’s no need for a multi-language plugin.
    For example why would I need WPML for a site in English?
    It doesn’t matter if the visitor is from USA, Canada or UK – they’ll all understand the content, but the OpenGraph data will point only towards one country depending on the selected WP language instead of all of them.

    Hello,

    The purpose of the og:locale:alternate is just to indicate to platforms that use the OpenGraph protocol that a particular page can be translated into different languages. You are just adding the same language but for different countries, so there’s no real benefit in doing that.

    In your particular case, if you only have a language on the website, you should rely on the og:locale that can be overridden with the filter we shared previously.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Alternative OpenGraph Locales’ is closed to new replies.