Adding “hreflang” tags to specific pages in Rank Math PRO

#706749
  • Resolved Selda Akin
    Rank Math free

    Hello,

    I’d like to ask you a question about the “hreflang” tags.

    One of our clients (https://www.rosenfeldinjurylawyers.com/) uses Rank Math PRO. Their site isn’t multilingual, however, they’d like to publish Spanish versions of some of the EN pages. In this case, we need to add the relevant hreflang annotations to specific pages. Could you please help us with this, and let us know how to proceed?

    Hope to hear from you soon.

    Best,
    Selda

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

    We appreciate your query about adding “hreflang” tags to specific pages in Rank Math PRO. While Rank Math PRO automatically handles “hreflang” tags for multilingual websites, it doesn’t add translated pages to the sitemap files, as it’s one of the recommended methods to do so.

    However, if you’d like to manually add “hreflang” tags to specific pages, you can do so by adding the tags directly to the HTML of the pages. Here’s an example of how the “hreflang” tag should look:

    In this example, replace https://rankmath.com/kb/multiple-languages-seo-rankmath-translatepress/ with the actual URL of the Spanish version of the page.

    If you have any further questions or need assistance with this process, please feel free to reach out. We’re here to help!

    Best regards.

    Sources:
    Why Are My Translated Pages Not in the Sitemap? » Rank Math
    Multilingual SEO with Rank Math SEO & WPML » Rank Math
    About and Mentions Schema » Rank Math
    How to Perform SEO for Multiple Languages Using Rank Math and TranslatePress » Rank Math

    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.

    Please note that Rank Math usually only handles adding the default language.

    Other languages are handled automatically by the translation plugin you use by adding a hreflang into each page automatically so that Google knows that it is a translated version of some other page.

    The hreflang tags are not handled by Rank Math, rather, we let the translation plugins generate these tags.

    Kindly contact the translation plugin support to address the issue further.

    We hope that helps, and please don’t hesitate to get in touch if you have any other questions.

    Thank you.

    Hey Alhan,

    Thank you for your email, however, our client doesn’t use a translation plugin. They handle the process by themselves! Therefore, your recommendation doesn’t work for them. Is there a way to add custom code (hreflang tags) to specific pages?

    Hope to hear from you soon.

    All the best,
    Selda

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience this issue may have caused you.

    You’ll be able to change the og:locale per post basis by using your post or page ID like this one:

    add_filter( "rank_math/opengraph/facebook/og_locale", function( $content ) {
        global $post;
        if($post->ID === YOU_POST/PAGE_ID_HERE){
            $content = 'es_US';
        }
        return $content;
    
    });

    You can also change it by your post/page URL:

    add_filter( "rank_math/opengraph/facebook/og_locale", function( $content ) {
    	$url = home_url( $_SERVER['REQUEST_URI'] );
    	if (strpos($url,'/blog/your-post-or-page-url-goes-here/') !== false) {
    	    $content = 'es_US';
            }
        return $content;
    });

    Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps and please don’t hesitate to let us know if you have any other questions.

    Thank you.

    Hey Alhan,

    Thank you for your quick response.

    Sorry to say that but it has been a little bit confusing. Our client will translate the following page into Spanish: https://www.rosenfeldinjurylawyers.com/sexual-abuse-lawyer/dr-ortega-northshore-health-system-claims/ Therefore, we’ll only have the EN & ES versions of this page.

    All we’d like to do is to add the below code to the <head> section of both pages. We didn’t understand how to fix it by changing the “og:locale” tags.

    <link rel=”alternate” href=”https://www.rosenfeldinjurylawyers.com/sexual-abuse-lawyer/dr-ortega-northshore-health-system-claims/&#8221; hreflang=”en-us” />
    <link rel=”alternate” href=”Add the URL of the ES version” hreflang=”es-us” />

    Looking forward to hearing from you soon.

    Best,
    Selda

    Hey Alhan,

    Thank you for your quick response.

    Sorry to say that but it has been a little bit confusing. Our client will translate the following page into Spanish: https://www.rosenfeldinjurylawyers.com/sexual-abuse-lawyer/dr-ortega-northshore-health-system-claims/ Therefore, we’ll only have the EN & ES versions of this page.

    All we’d like to do is to add the below code to the <head> section of both pages. We didn’t understand how to fix it by changing the “og:locale” tags.

    <link rel=”alternate” href=”https://www.rosenfeldinjurylawyers.com/sexual-abuse-lawyer/dr-ortega-northshore-health-system-claims/&#8221; hreflang=”en-us” />
    <link rel=”alternate” href=”Add the URL of the ES version” hreflang=”es-us” />

    Looking forward to hearing from you soon.

    Best,
    Selda

    Hello,

    Unfortunately, our plugin does not have control of the hreflang of your site. We rely on multi-language plugins to do that.

    In this case that you are not using a translation plugin or not going to use one, then you may need to use a different plugin that specifically addresses this like Hreflang Manager.

    Hope that helps.

    Thank you.

    Hi Reinelle,

    Hope you had a lovely weekend!

    Just a warm reminder of my message above.

    All the best,
    Selda

    Hi Reinelle,

    Thank you for your kind response.

    I’ve come across the below solution about adding our custom “hreflang” tags to specific pages. Could you please review it, and let me know if it works?

    Install and Activate “Rank Math Pro”
    Ensure that Rank Math Pro is installed and activated on your WordPress website.

    Edit the Specific Page
    Go to the WordPress dashboard, navigate to the page where you want to add the “hreflang” annotation.

    Find “Rank Math Meta Box”
    Scroll down to the Rank Math SEO meta box, which is usually below the main content area of your page editor.

    Click “Advanced Tab”
    In the Rank Math meta box, click on the “Advanced” tab. This tab allows you to configure advanced SEO settings for the page.

    Include Custom Code in Header
    Look for an option to add custom code in the header. Rank Math Pro should provide a field where you can input custom code that will be added to the <head> section of the specific page.

    Add Hreflang Tags
    In the custom code field, add your “hreflang” tags.

    Replace the URLs and hreflang values with those that are appropriate for your website and target audience.

    <link rel=”alternate” href=”https://www.example.com/page&#8221; hreflang=”en” />
    <link rel=”alternate” href=”https://www.example.com/es/pagina&#8221; hreflang=”es” />

    Save Changes
    After adding the code, save or update the page. The “hreflang” tags will now be present in the HTML head of that specific page.

    Verify
    Once you’ve added the tags and updated the page, it’s a good practice to check the page’s source code to ensure that the “hreflang” tags are correctly implemented. You can view the page source by right-clicking on the web page and selecting “View Page Source” or similar, depending on your browser.

    Best,
    Selda

    Hello,

    The solution you shared in the previous message won’t work as we don’t have the options in our plugin that were illustrated in the answer.

    As our team already mentioned, we don’t have a way to handle the hreflang tag on the website so you need to either use custom code to add it or install a translation plugin.

    Don’t hesitate to get in touch if you have any other questions.

    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 10 replies - 1 through 10 (of 10 total)

The ticket ‘Adding “hreflang” tags to specific pages in Rank Math PRO’ is closed to new replies.