include query string to sitemap

#875018
  • Resolved Raymond
    Rank Math free

    Hi Support

    How do I include custom query string on products to sitemap. My shop uses query string to switch currency by adding this at the end of url: ?wmc-currency=AUD

    There are four currencies in total.
    ?wmc-currency=AUD
    ?wmc-currency=GBP
    ?wmc-currency=NZD
    ?wmc-currency=CAD
    and for USD, no query string require.

    So each of my product category, shop page, and product page will need the extra query string added.
    I read from the support page, you can actually add custom query string on sitemap but I cannot find this setting.

    Thank you

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

    We apologize for the issue you are facing with including custom query strings in your sitemap. Currently, there isn’t a direct setting in Rank Math to add query strings to the sitemap for product pages or categories. However, you can achieve this by using a custom filter in your theme’s functions.php file.

    Here’s how you can add the custom query strings for your products:

    1. Open your theme’s functions.php file.
    2. Add the following code snippet:
    /**
     * 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/product_content', function() {
        return '
            https://rankmath.com/wp-content/uploads/2021/02/include-in-sitemap-2.jpg
            2020-06-10T20:20:20+00:00
        ';
    });
    1. Replace `https://rankmath.com/wp-content/uploads/2021/02/include-in-sitemap-2.jpg with the actual URL of your product pages and repeat this for each currency you want to include.

    This will allow you to manually add the URLs with the query strings to your sitemap.

    For more detailed guidance on configuring sitemaps, you can refer to our knowledgebase article.

    If you have further questions or need assistance with this implementation, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further.

    Thank you for raising this concern!

    Raymond
    Rank Math free

    Hi Support

    How do I do this if I want to include for all products? Because adding this code individually seems very heavy under the function.php file

    Hello,

    Unfortunately, you may need to use the filter to add the parametered URLs to the sitemap as Rank Math does not support adding those.

    However, you may customize the filter to apply them to all your products without including all the URLs in the sitemap, but it is already out of our scope of support.

    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 ‘include query string to sitemap’ is closed to new replies.