Hello @mevabien22,
Thank you so much for getting in touch.
Yes, we do have a PHP code for excluding URLs from the sitemap.
Here’s an example code on how to do it:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){ if($url == 'https://mywebsite.com/some-post/'){ return false; } return $url; }, 10, 3 );
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thank you very much for the response, but unfortunately the code provided does not work, I have changed the url to that of the page I want to exclude but it has not worked…
Hello @mevabien22,
Please try the code below instead:
add_filter('rank_math/sitemap/entry', function ($url, $type, $object) { if ($url['loc'] == 'https://mywebsite.com/some-post/') { return false; } return $url; }, 10, 3);
If the issue persists, please follow the steps below:
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/
3. Apply the following filter code to your site:
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
That should resolve the issue.
Hope that helps.
thank you very much, it works very well now!
Hello @mevabien22,
Glad that helped.
If it isn’t too much to ask for, would you mind leaving us a review here?
https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post
It only takes a couple of minutes but helps us tremendously.
It would mean so much to us and would go a long way.
Thank you.