Hello,
Thank you for reaching out to us regarding the issue with your Rank Math sitemap. To remove the unwanted rewrite slug URL from your sitemap.xml, you can follow these steps:
- Open your theme’s
rank-math.php
file.
- Add the following code snippet to exclude the specific URL from the sitemap:
add_filter( 'rank_math/sitemap/entry', 'remove_specific_url_from_sitemap', 10, 3 );
function remove_specific_url_from_sitemap( $url, $type, $post ) {
// Check if the URL matches the one you want to exclude
if ( 'YOUR_URL_TO_EXCLUDE' === $url['loc'] ) {
return false; // Exclude the URL from the sitemap
}
return $url;
}
Replace 'YOUR_URL_TO_EXCLUDE'
with the URL you want to remove from the sitemap.
If you encounter any difficulties or need further assistance, please feel free to reach out. Thank you for your understanding.
Warm regards,
Sources:
Rank Math Sitemap Issues and Their Fixes » Rank Math
Why the Sitemap_Index.xml is Throwing a 404 Error » Rank Math
Multilingual SEO with Rank Math SEO & WPML » Rank Math
Hello Support,
Thanks for Reply.
We have tried with above snippet code and we have put our url in this filter but its not working yet and not remove from sitemap.xml. We need to remove from xml url like this https://www.bacancytechnology.com/case-study/case_study
Please give us to alternate option/solution for this.
Thank you
Hello,
Thank you for contacting us and sorry for any inconvenience that this issue might have caused.
It appears Rank Math is not activated on your site at the moment.
Please follow the steps below for initial troubleshooting:
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/
If the issue persists then try disabling the transient cache for the sitemap. This will make sure that your XML sitemap always reflects the latest changes on your site. To do this, you need to add a small piece of code to your site’s functions.php file or use a plugin like Code Snippets.
The code you need to add is this:
/**
* Filter if XML sitemap transient cache is enabled.
*
* @param boolean $unsigned Enable cache or not, defaults to true
*/
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
If you’re not sure how to add this code, you can follow this guide: https://rankmath.com/kb/wordpress-hooks-actions-filters/.
It will show you step-by-step how to use the Code Snippets plugin or edit the functions.php file safely.
After you add the code, please clear any cache on your site or server and check your XML sitemap again. If you’re still facing issues with the sitemap, please let us know – we are happy to investigate further.
Hello Supports,
Thanks for reply us. We have tried also clear cache using wp rocket premium version but still it not removed from sitemap. Can you please suggest another solution like hard code snippet or remove from WordPress hook?
Thanks
Hello,
The URL https://www.bacancytechnology.com/case-study/case_study appears to be set to index and its canonical URL is self-referencing. For that reason, it will be included in the sitemap by default.
You can use the Exclude Posts
option in the sitemap settings to exclude that page from the sitemap. Please refer to this guide: https://rankmath.com/kb/exclude-content-from-sitemap/
Please note that some options are only available in Advance Mode. If you are not able to find the Exclude Posts option in the Sitemap Settings, please try to switch to Advance Mode: https://rankmath.com/kb/switch-from-easy-to-advanced-mode/
Hope that helps and please don’t hesitate to let us know if you have any other questions.
Thank you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.