Include custom canonical posts in the Rankmath sitemap

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

    Thank you for contacting Rank Math and bringing your concern to our attention.

    If you have set up a custom canonical URL in Rank Math, then those URLs won’t be included in the sitemap by default:
    https://rankmath.com/kb/url-not-in-sitemap/#custom-canonical-url

    However, if you wish to add them manually to your sitemaps, you can use the filter available here: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-urls-in-sitemap

    /**
     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>2023-06-10T20:20:20+00:00</lastmod>
    </url>';
    });

    Then, replace {$type} with the type of sitemap you have (post, page, etc.).

    Hope that helps.

    Thank you.

    Thank you! Made small changes to the code and added posts from a specific category and it worked!

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

The ticket ‘Include custom canonical posts in the Rankmath sitemap’ is closed to new replies.