-
Hi!
I’ve setup sitemap to exclude certain categories, but they are still in the list.
I’ve added 3 categories to be excluded (5,477,478), it’s news and test posts, even pages that’s been marked no index are on the list..
This is the current list, and only one of them should be on the list (see screenshot)
-
I’ve kept on we working, but no solution, I’m not sure it even runs..
Hello,
The code we gave you will add a noindex to all the posts in the
477
category.However, that will not exclude them from sitemap files as for a post to be excluded from the sitemap, it has to be set as noindex using the plugin’s UI options.
We are afraid we do not have an option for you to automatically noindex all posts in a category AND exclude them from the sitemap. We can only help you do the first one.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Hi again!
Ok, eh, however, the post don’t get the noindex flag, not with that code.
Not with that code in the functions.php, at least not the ‘flag’ you can see in the RankMath advanced section of the post..
And I guess I can turn of the sitemap functions, I have to find a third party sitemap function, because my only other choice is Yoast, It works, but they say yours are better..
Hello,
I guess the no-index tag is being added but since it was not added using the UI, it is not showing as added in the Advanced Tab (the same that happens to don’t have that post excluded from the sitemap since it was not done through the UI).
If you see in the source code the no-index tag, everything is working fine. If not, just let me know and we will check it.
Looking forward to help you.
.. Now you lost me…
Let’s number the question..1. The code adds a noindex flag to the post if it has one of the listed categories.
But it will add the post url to the sitemap anyway..
Have I got that correct?
2. The exclude terms doesn’t exclude posts in that term, it just do what?
I might add, that both Yoast and the plug-in Google xml-sitemap (that I’m currently testing) does exclude the posts in the excluded categories.
3. If the noindex flag is set on a post, how do I see it if it’s not showing in the advanced settings on that post…?
Hi Adam,
1.Yes, and yes.
2. It excludes the term itself – not the contents of the term. For example, if you are excluding “177” and that term is a tag called “Google” – the
domain.com/tag/google
URL will be excluded from the Sitemap. Any posts that have the “Google” tag will not be excluded from the sitemap.3. By going to the post and heading to the Advanced tab of Rank Math you can check if the post has been set as noindex or not:
https://i.rankmath.com/51vE4rHope that helps and please do not hesitate to let us know if you need our assistance with anything else.
1. The first yes I understand, but I don’t understand why you need to put a post in the sitemap, if you don’t want it indexed…
2. Ok..
3. I was referring to if the post has been set to noindex via the script (as Alberto wrote in the previous answer)
But I’m currently not using the sitemap function on RankMath, since it can’t do what I’m after..
Hi Adam,
1. You do not want your noindex posts to be in the sitemap. But, there is no way for us to detect the noindex tag unless you set it using the advanced tab or using the UI. If you use the code we gave you to noindex, the sitemap function will not see the noindex and hence it won’t know that it should exclude that post.
3. You can enter the URL on this page to check if it has been set as noindex: https://smallseotools.com/meta-tags-analyzer/
Do you see that function in any other Sitemap plugin? We would love to know.
Hi!
Thx for the answer.3. Yes, Yoast can skip all post in a specific category (don’t add it to sitemap), and also Google xml-sitemap (from WordPress plug-in site) can disregard all post in a specified category..
So at the moment I’m using RankMath to everything except sitemap, which I’m using the Google xml-sitemap plug-in.
I would prefer all in one plug-in, but since RankMath seems to be the best on all other parts, it seems like I’m going to have to run 2 plug-ins..
Hello,
Well, I am happy to hear you like Rank Math and don’t worry, I have notified devs about your suggestion, so I hope they will add that function in a future update so you will be able to use just one plugin for everything.
Looking forward to help you.
Hello,
As far as I know, Yoast does not have any option to exclude the posts from Sitemap. Were you using any filter for this? In Rank Math, you can exclude the posts by category by using the following filter:
https://rankmath.com/kb/filters-hooks-api-developer/#filter-sitemap-itemThis filter runs before the post is added to the sitemap so you can use it to check if current post has the catgory and exclude it accordingly by returning null. Here is an example:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){ if ( 'post' !== $type ) { return $url } $terms = wp_get_object_terms( $object->ID, 'taxonomy-name', [ 'fields' => 'ids' ] ); if ( in_array( 'CAT_ID', $terms ) ) { return ''; } return $url; }, 10, 3 );
I hope that helps.
Did you manage to get this to work? I need the same
Hello,
You can try applying the following filter to exclude all posts within a given category from your sitemap:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){ $post_id = $object->ID; if( has_term( 111, 'category', $post_id ) ) { // Change 111 to the ID of the category $url = false; } return $url; }, 10, 3 );
Hope this helps solve your issues.
Don’t hesitate to get in touch if you have any other questions.
The ticket ‘Excluded categories still in sitemap’ is closed to new replies.