Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
Yes, to clear the custom sitemap cache, you’ll have to execute the \RankMath\Sitemap\Cache::invalidate_storage( ‘amp’ ); on save_post
hook.
However, if you’re not sure how to do it, we would recommend you disable the sitemap cache completely by adding the filter you have shared.
Hope that helps.
Thank you.
Hi Reinelle, my problem isn’t clean in save_post but add a new sitemap without add the filter to disable cache. I attach my code, maybe I forgot something?
/**
* Add new sitemap
*/
add_filter( 'rank_math/sitemap/index', function( $xml ) {
$midnight = strtotime("today 00:00");
$xml .= '
<sitemap>
<loc>'. get_site_url() . '/test-sitemap.xml</loc>
<lastmod>' . date('c', $midnight) . '</lastmod>
</sitemap>';
return $xml;
}, 11 );
/**
* Add link to sitemap (I've modded this filter)
*/
add_filter( 'rank_math/sitemap/soci/content', function() {
return '<url>
<loc>https://rankmath.com/some-custom-url/</loc>
<lastmod>2020-06-10T20:20:20+00:00</lastmod>
</url>';
}
Best regards
Hello,
If you do not wish to use that filter code to disable file caching of sitemaps, please make sure that your plugins aren’t caching the sitemaps. You may refer to the steps below to do just that:
1. Flush the Sitemap cache by following this video screencast:
https://i.rankmath.com/pipRDp
2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
https://rankmath.com/kb/exclude-sitemaps-from-caching/
Let us know if that works for you.
Looking forward to helping you. Thank you.
Hello again,
We are glad to hear that this issue has been resolved. Thank you for letting us know. This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.
We appreciate your patience and cooperation throughout this process.
Thank you for choosing Rank Math.