Meta tag op: locale

#581851
  • Resolved Analia Castro
    Rank Math free

    Good morning,

    I was wondering if you can help me to configure the op:locale meta tag in the case of “ES_AR”. Currently it is set to “ES_ES”.

    In the other languages we have if we see it fine.

    I look forward to your prompt reply,

    Regards,

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

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    The language code in Rank Math’s og:locale meta tag will depend on the default site language you have set up in WordPress. You can find it on your WordPress dashboard > Settings > General > Site Language

    locale

    However, you can use this filter to change it on your site:

    /**
     * Allow developers to change the content of specific social meta tags.
     *
     * The dynamic part of the hook name. $network, is the network slug
     * and $og_property, is the property which we are outputting.
     *
     * @param string $content The content of the property.
     */
    add_filter( "rank_math/opengraph/facebook/og_locale", function( $content ) {
            $content = 'ES_AR';
    	return $content;
    
    });

    The filter should be added to your active theme’s functions.php file. Here’s another way to apply the filter using the rankmath.php file:
    https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php

    Hope that helps.

    Thank you.

    Reinelle,

    In WP settings we have ESPAÑOL DE ARGENTINA and anyway the meta tag is created with “es_ES”.
    The code you give me is useful to change it but it modifies the other languages we have, as it is a multilingual site.
    Los codigos correctos deberian ser asi:
    “es_AR”
    “en_US”
    “pt_BR”
    “de_DE”

    Hello,

    Thank you for contacting Rank Math support.

    We’re sorry to hear that you’re having an issue with the og:locale meta tag on your multilingual site. We understand that you want to have the correct language code for each language on your site.

    To achieve this, you need to use a filter that can detect the current language of your site and change the og:locale meta tag accordingly.

    Here’s a code snippet that shows how to use the rank_math/opengraph/facebook/og_locale filter with Weglot to change the og:locale meta tag based on the current language.

    You can use this code snippet as a reference and modify it according to your multilingual plugin and language codes. The code snippet should be added to your active theme’s functions.php file or rankmath.php file.

    Here is the code snippet:

    php
    /**
     * Change og:locale based on current language
     */
    add_filter( 'rank_math/opengraph/facebook/og_locale', function( $content ) {
    	// Get current language from Weglot
    	$current_language = weglot_get_current_language();
    
    	// Define language codes for each language
    	$language_codes = array(
    		'es' => 'es_AR',
    		'en' => 'en_US',
    		'pt' => 'pt_BR',
    		'de' => 'de_DE',
    	);
    
    	// Check if current language has a defined code
    	if ( isset( $language_codes[ $current_language ] ) ) {
    		// Change og:locale to the defined code
    		$content = $language_codes[ $current_language ];
    	}
    
    	return $content; 
    });

    We hope this helps you with your issue. If you have any questions or issues, please feel free to contact us again.

    Best regards

    Great,
    I have no knowledge of how to edit this tag you send me to make it fit our site.
    We currently use a plugin called Polylang for multilanguage.
    Is there any way I can send you an attached image to show what I want to explain?

    Hello,

    Thank you for contacting Rank Math support and for providing additional information about your multilingual plugin. I’m sorry for the inconvenience this issue may have caused you.

    I see that you’re using Polylang. Polylang has a handy function called pll_current_language() that you can use to get the current language of your site and change the og_locale meta tag accordingly.

    Here’s what your code would look like:

    /**
     * Allow developers to change the content of specific social meta tags.
     *
     * The dynamic part of the hook name. $network, is the network slug
     * and $og_property, is the property which we are outputting.
     *
     * @param string $content The content of the property.
     */
    add_filter( "rank_math/opengraph/facebook/og_locale", function( $content ) {
            // Get the current language code
            $language = pll_current_language('slug');
            // Set the op:locale meta tag based on the language code
            switch ($language) {
                case 'es':
                    $content = 'es_AR';
                    break;
                case 'en':
                    $content = 'en_US';
                    break;
                case 'pt':
                    $content = 'pt_BR';
                    break;
                case 'de':
                    $content = 'de_DE';
                    break;
                default:
                    // Keep the default value
            }
    	return $content;
    
    });

    This filter will dynamically change the op:locale meta tag based on the current language code of your site. Add the code to your website and let me know if it successfully achieves your need. Learn more on how to add filters to your site here: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    PS: You can use imgur.com/upload to share screenshots and loom.com to share screencasts. Also, the credential you shared in the sensitive data section is not complete, you did not include your site URL.

    I hope this helps. Please let me know if you have any questions or concerns.

    Thank you.

    Hello, good afternoon,

    I have tried the code and it does not modify the OP tag.
    Is it possible that polylang is stepping on it and can not be modified?
    Is it possible that this tag is equal to
    html lang=”en_AR”
    html lang=”de”
    html lang=”pt_BR” html lang=”pt_BR”
    html lang=”en” html lang=”en”

    Hello,

    I’ve checked the site connected to your account, and the og:locale is showing fine. Please refer to the screencast attached in the sensitive data section.

    Could you please confirm if you’re referring to other tags (OP tag) than that?

    Meanwhile, it seems that you’re using Rank Math PRO but the account you have used to open this ticket is the Rank Math free version.

    Can you please search and forward a receipt from FastSpring.com or the email address you used to purchase so we can locate your account and verify it?

    Looking forward to helping you.

    Thank you.

    Hello, good morning,

    [moved to sensitive data section]

    On the other hand, I see that the OP tag is showing the following:
    <meta property=”og:locale” content=”en_US” />
    and I would like it to be displayed:
    <meta property=”og:locale” content=”es_AR” />
    how to display our html lang tag:
    <html lang=”en-AR” prefix=”og: https://ogp.me/ns#”&gt;

    I look forward to your comments,

    Hello,

    Thank you for the clarification.

    I’ve activated the snippet in your site from my colleague above, and the og:locale tags display the correct values.

    Regarding the hreflang tags, they are controlled by your multilingual plugin so you may get in touch with their team to update them accordingly on your site.

    Hope that helps.

    Thank you.

    Rainell,

    Thank you very much, I see it’s solved.

    Alhan
    Rank Math free

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘Meta tag op: locale’ is closed to new replies.