custom post status in sitemap

  • Hi,
    How can i choose custom post status to be included in the sitemap? currently only ‘publish’ status are added.


    • This topic was modified 2 years, 1 month ago by Yaniv Harush.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math today.

    This feature is not available but you can add some custom code to fetch the posts and add them to the sitemap. Please take a look at the example below for some guidance. This code should go to your 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() {
    function rank_math_add_custom_dynamic_url( $urls ) {
        $urls .= '
        $urls .= '
        return $urls;

    I hope this info helps. Thank you.


    Hi Micheal,

    Thanks for addressing me to this hook.
    I had to modify it a bit, the sample above just echos the string to the xml but not formatted.

    it should be like this:

    $urls .= "<url>

    Its working for me now, so thanks!

    it would be great if you could add a filter to the query that builds the sitemap.


    Hi Yaniv,

    Thanks for the follow up.

    I am glad that you were able to make this work 🙂

    Don’t hesitate to contact us should any other issues come up.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘custom post status in sitemap’ is closed to new replies.