force a refresh of the xml sitemap

#27106
  • Resolved James Pascale
    Rank Math free

    How do I force a refresh of the xml sitemap?
    I understand that Rankmath will automatically refresh the sitemap when I change a page or a post.
    However, I sometimes interact directly with the mySQL database (to edit or delete some posts) using SQL & not using WordPress functions. When I do this, I don’t think it triggers RankMath to refresh the sitemap. In these instances, I need a way to trigger RankMath to refresh the sitemap.

    Thanks.

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

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    You can refresh the sitemap by doing the following:

    1. Head over to WordPress Dashboard > Settings > Permalinks

    Hit the save button once.

    2. Go to WordPress Dashboard > Rank Math > Sitemap Settings

    Hit the save button once.

    If it doesn’t, please do let us know so we can look at this further.

    Michael, thanks!

    Is there a way to do this programmatically?
    For example, if I run the execute: /wp-admin/options-permalink.php,
    does this do the same thing as hitting the save button in step 1 above?

    Thakns!

    Hello,

    Thank you for the response.

    I am not sure that this would work in this case. I can suggest that you take a look at this function instead:
    https://developer.wordpress.org/reference/functions/flush_rewrite_rules/

    There are a few examples on Google on how you can programatically trigger flushing of the rewrite rules.

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Michael, thanks!
    I wasn’t aware of that function & didn’t know enough to know how to search for it. I’ve read the documentation on flush_rewrite_rules(). So that should take care of step 1. Is there a function or php file I can call that will perform step 2? Or is that not needed?

    1. Head over to WordPress Dashboard > Settings > Permalinks

    Hit the save button once.

    2. Go to WordPress Dashboard > Rank Math > Sitemap Settings

    Hit the save button once.

    Hi James,

    Thanks for the follow up.

    The first step is the most important when directly adding links to the database since the second is not required most of the time.

    I am however consulting our dev team about this and I will be in touch in a short while.

    We appreciate your patience. Thank you.

    👍

    Hello,

    Like my colleague suggested, you can use flush_rewrite rules() function to clear the Sitemap cache. Or you can disable the Sitemap cache by adding the following function in your theme’s functions.php file:
    https://rankmath.com/kb/filters-hooks-api-developer/#enable-disable-sitemap-cache

    You can set it to false to disable the Sitemap cache.

    I hope that helps. Thank you.

    Pratique, thanks!

    So, just to make sure that I understand how all of this works:
    your method (use RM filter) & Michael’s method (WP rewrite function) both eliminate the sitemap cache.
    So what triggers Rankmath to create a new site map? Is it when Google reads the file?

    Hi James,

    Apologies for the delay.

    With the cache disabled, the plugin will be able to detect newly added links and update the sitemap on the fly.

    I hope this info helps.

    Michael, got it.
    Thanks!

    Todd
    Rank Math free

    Hi James,

    We are so glad to be of help. We are always here if you need us in the future.

    Hey, if it isn’t too much to ask for – would you mind leaving us a review here?

    https://s.rankmath.com/reviewrm

    It only takes a couple of minutes but helps us tremendously.

    It would mean so much to us.

    Thank you.

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

The ticket ‘force a refresh of the xml sitemap’ is closed to new replies.