Help Needed: Remove XSL Stylesheet and Add Hreflang Entries to Site

#1050374
  • Resolved Vsevolod Krasovskyi
    Rank Math free

    Hello Rank Math Support,

    We are using Rank Math SEO (v1.0.246) and would like to:

    Remove the XML stylesheet declaration (XSL)

    Add <xhtml:link> hreflang tags inside each <url> block in the generated XML sitemap, for example:


    <url>
    <loc>https://site.com/sample-url/</loc>
    <xhtml:link rel="alternate" hreflang="bg" href="https://site.com/sample-url/" />
    <xhtml:link rel="alternate" hreflang="en" href="https://site.com/en/sample-url/" />
    </url>

    Please let us know how to properly achieve both modifications using Rank Math.

    Thank you!

    Best regards,

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

    We apologize for the issue you are facing. To remove the XML stylesheet declaration (XSL) and add hreflang entries to your sitemap in Rank Math, you can follow these steps:

    1. Remove the XML Stylesheet Declaration

    To remove the XSL stylesheet declaration from your sitemap, you can add a filter to your theme’s rank-math.php file. Here’s how:

    1. Navigate to WordPress Dashboard → Appearance → Theme File Editor.
    2. Select the rank-math.php file from the right sidebar.
    3. Add the following code at the end of the file:
      add_filter( 'rank_math/sitemap/xsl', '__return_false' );
    4. Click on the Update button to save your changes.

    2. Add Hreflang Entries to Your Sitemap

    To add hreflang tags inside each ` block in your generated XML sitemap, you can use a similar approach by adding a filter in the samerank-math.php` file:

    1. In the same rank-math.php file, add the following code:
      add_filter( 'rank_math/sitemap/entry', function( $url ) {
         // Add hreflang tags here
         $url['xhtml:link'] = [
             [ 'rel' => 'alternate', 'hreflang' => 'bg', 'href' => 'https://support.rankmath.com' ],
             [ 'rel' => 'alternate', 'hreflang' => 'en', 'href' => 'https://support.rankmath.com' ]
         ];
         return $url;
      }, 10, 1 );
    2. Make sure to replace the URLs with your actual URLs for each language.
    3. Click on the Update button to save your changes.

    Important Note

    Before making any changes to your theme files, we recommend taking a backup of your website’s files and database to prevent any data loss.

    If you need further assistance or if these modifications do not work as expected, please reply to this ticket, and a human agent from our support team will assist you further.

    Thank you for raising this concern!

    Sources:
    How to Fix "Incorrect HTTP Header Content-Type" Error in Sitemaps » Rank Math

    Hello,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    At the moment, Rank Math doesn’t offer a built-in way to remove the XML stylesheet declaration or add hreflang tags within each <url> block in the sitemap. Hreflang implementation is typically managed by translation/multilingual plugins.

    If you’re using a compatible translation plugin, it should handle hreflang output automatically.

    Don’t hesitate to get in touch with us 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 2 replies - 1 through 2 (of 2 total)

The ticket ‘Help Needed: Remove XSL Stylesheet and Add Hreflang Entries to Site’ is closed to new replies.