Hello,
Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.
The filter you are using runs only when the page is loaded on a browser, and because of that, the URLs will still be set to index when the sitemap functions run.
It’s correct that the noindex URLs would not be included, but this is a very particular case.
You may need to use and customize this filter to remove the URLs from the sitemap as well: https://rankmath.com/kb/filters-hooks-api-developer/#filter-sitemap-item
I hope that helps.
Thank you.
Could you provide an example of how to use that hook to do that please?
Hello,
Here’s an example that removes any URL containing the word review in the URL:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
if( strpos( $url['loc'], 'review' ) && $type == 'post' ){
return false;
}
return $url;
}, 10, 3 );
Hope this helps solve your issues.
Don’t hesitate to get in touch if you have any other questions.
Hello,
We are super happy that this resolved your issue.
If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.