How to add hreflang tags in sitemap without plugin?

#283095
  • Resolved rankmath lover
    Rank Math pro

    I have a multilingual wordpress sites which should use the hreflang tags.
    I already enabled the multisite subdirectories for the site without plugin.
    Any way to manually edit the sitemap in Rankmath and add the hreflang tags in it for better seo?

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

    Thanks for contacting us and sorry for any inconvenience that might have been caused due to that.

    The hreflang tag is added to the posts and pages. It is not added inside the sitemap.

    Unfortunately, our plugin does not have control of the hreflang of your site. hreflang tags are usually added automatically if you have a translation plugin. Since you’re not using a translation plugin, you can refer to the following articles for more help:
    https://moz.com/learn/seo/hreflang-tag
    https://www.wpbeginner.com/plugins/how-to-add-hreflang-tags-in-wordpress/

    Hope this helps. Let us know if you need any further assistance.

    I have seen you two articles. Thank you for your quick answer.
    I do know that hreflang good for seo and I do know the correct hreflang format and the method to generate.
    Only one thing I don’t know is that how to insert generated hreflang tags in the rankmath sitemap?
    And I do know that I can insert these in header.php but this header method makes the site load very slow. The best way to do it is inserting hreflang in sitemap.

    Anas
    Rank Math business

    Hello,

    The hreflang tag needs to be added to the pages.

    To add the language URLs in the sitemap, you can modify this filter and add it to the theme’s functions.php file.

    /**
     Filter to add extra URLs to the XML sitemap by type.
     *
     Only runs for the first page, not on all.
     *
     @param string $content String content to add, defaults to empty.
     */
    add_action( 'rank_math/sitemap/{$type}_content', function() {
    return '<url>
    <loc>https://rankmath.com/some-custom-url/</loc>
    <lastmod>2020-06-10T20:20:20+00:00</lastmod>
    </url>';
    });

    Replace {$type} with either post or page depending on if you want the URL to be included in the post or page sitemap – respectively.

    I hope this helps. Looking forward to helping 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 3 replies - 1 through 3 (of 3 total)

The ticket ‘How to add hreflang tags in sitemap without plugin?’ is closed to new replies.