-
Hi!
I read the instructions in https://rankmath.com/kb/exclude-content-from-sitemap/, and entered 5 in the settings, as the ID number for the category I want to exclude, yet are the posts with that category show in the XML file
I’ve also added this code to rank-math.php in my theme directory (from a previous conversation with your support (4 years ago);<?php
/**
* Filter to set noindex to specific categories
*/
add_filter( 'rank_math/frontend/robots', function ( $robots ) {
$categories = array_map( function ( $category ) {
return $category->slug;
}, get_the_category() );//Replace your_category with your category slug.
if ( in_array( 'donotallowpost', $categories ) ) {
unset( $robots['index'] );
$robots['noindex'] = 'noindex';
}
return $robots;
} );
?>
-
Hello,
I apologize for the inconvenience you are facing with excluding a specific category from the sitemap in Rank Math. Thank you for providing the details and screenshots.
It seems like you have followed the correct steps by entering the ID “5” for the category you want to exclude in the settings, but the posts with that category are still showing in the XML file.
To troubleshoot this issue, please ensure that you have entered the correct category ID and that there are no typos or extra spaces. Additionally, make sure that the code snippet you added to the rank-math.php file is correctly implemented.
If the issue persists after verifying the category ID and checking the code snippet, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further.
Thank you for your understanding and patience.
Sources:
How to NoIndex All Posts in a Category » Rank Math
How to NoIndex All Posts in a Category » Rank Math
How to Exclude Content From Sitemap » Rank Math
How to Configure Sitemaps in Rank Math – Best Settings and Tips
Why the Sitemap_Index.xml is Throwing a 404 Error » Rank MathHello,
Thank you for your patience.
Your site is under construction mode, so we’re unable to see the sitemap.
However, please follow these steps to flush your sitemap cache for initial troubleshooting:
1. Flush the Sitemap cache by following this video screencast:
https://i.rankmath.com/pipRDp2. 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. Disable the transient cache for the sitemap by applying this filter. This will make sure that your XML sitemap always reflects the latest changes on your site:
/** * 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 the issue still persists, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
Please do take a complete backup of your website before sharing the information with us.
It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
We really look forward to helping you.
Hello,
Please note that excluding the terms from the sitemap will not exclude the posts associated with those terms. Only the terms pages will be removed from the sitemap.
However, if those terms are still present on the sitemap. We need to check your website.
We are working in different places around the world and our IP is dynamic so even if you whitelist our IP, we might not be able to access it as our IP has changed by the time we check this ticket again.
If you are using geo-blocking, please temporarily unblock the country Portugal, India, Nigeria, Bangladesh and the Philippines so we can further inspect your website.
Looking forward to helping you.
Ok, didn’t realize that, but them my questions goes back to the code I presented earlier, the one I got from you for a couple of years ago, why isn’t that preventing the posts from being indexed?
Hello,
We tried to check your pages but they are getting redirected to the https://rainbowpets.sesesese.se/ site.
The filter you’ve shared above should Noindex all the posts under the
donotallowpost
category. But it will not remove the posts from your sitemap. In order to remove all the posts from yourdonotallowpost
category, you can use the following filter on your website:add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ) { if ( $type === 'post' ) //change your post type here { $categories = get_the_terms( $object->ID, 'category' ); // Replace 'category-slug-1' with your actual category slugs $exclude_categories = array( 'donotallowpost'); if ( is_array( $categories ) && array_intersect( $exclude_categories, wp_list_pluck( $categories, 'slug' ) ) ) { return false; } } return $url; }, 10, 3 );
Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how it goes. Looking forward to helping you.
Thank you.
That seems to have solved it..
However, WHY is rankmath publishing the post/pages set to NO INDEX?, what’s the point.. the pages I don’t want to index, should not be on any lists, because I don’t wont them indexed…
So HOW do i tell rankmath to keep it’s hands off all the pages I don’t want listed, eg indexed? if it adds them to the list anyway?
Hello,
Please note that Rank Math by default doesn’t include the posts/pages that are set to Noindex.
But when you set your posts/pages to Noindex by using a filter, the sitemap functionality doesn’t work properly because the filter executes after Rank Math includes the posts/pages in the sitemap.
However, if you set your posts/pages to Noindex manually from the Rank Math SEO Meta box, it automatically removes them from your sitemap.
Hope that helps and please don’t hesitate to let us know if you have any other questions.
Thank you.Hi!
Actually, no, it don’t solve it, since I’m letting users to post the post from frontpage, and they don’t have access to those setting, and that’s why I have a category for “donotallowpost”, and if the users selects that category, it should not be indexed.
Hello,
Using the filter you shared earlier will set the posts to
noindex
, and the filter we shared will remove the posts from the sitemap.Unfortunately, the default is that the filter executes before Rank Math includes the posts/pages in the sitemap.
Manually setting the post to
noindex
can help remove the posts from the sitemap.Thank you.
Well, that don’t solve my issue..
a question, the point of rankmath, is to get for example google to index the site better?
and if the point of noindex is to tell the robot to not index the page?So.. why is then rankmath even publishing the link? – if a page has NOINDEX?
By publish the link, Rankmath are overriding my will, and publicly exposing pages I maybe don’t want to be exposed, since everybody can read the sitemap, even bad robots.Now, if the scripts i have, runs before the Rank Math includes the posts/pages in the sitemap, will the post / page, it be public, and therefore useless.
And as I have written earlier, I can’t set NOINDEX to the post manually, since it is other users that are publishing the posts, and the noindex is set by another script, based on what category the user are choosing.
I find it strange that a plugin that is suppose to show the pages that wants to be indexed, shows everything?
Strange, I’ve been testing, to do new post, it removes it from the siteindex file, but the first code, that is suppose to set it to noindex, isnt doing it anymore..
Hello,
In this case, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress logins in the designated Sensitive Data section.
Please do take a complete backup of your website before sharing the information with us.
It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
We really look forward to helping 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.
The ticket ‘exclude term not working?’ is closed to new replies.