I recently noticed on one of my sites that wordpress posts from a particular category were appearing in the site’s rss feed. That category was only meant for people who had the specific url. Not secure, I know, but we weren’t too worried if the urls got passed around. However, we didn’t want them in the rss feed.
After hunting around for a bit, I came across this from Ash Point Lane. The code is slightly different from Bruce’s because his seems to have corrupted slightly when he posted it. The problem in his php is the > which should be > and if you use the code as he has it, you’ll have to ftp into the functions.php file to fix it :(. Lesson learned.
So, add this code to your functions.php file. Change the number from 5 to the ID of the category you want to exclude.
function myFilter($query) {
if ($query->is_feed) {
$query->set(‘cat’,’-5‘);
}
return $query;
}
add_filter(‘pre_get_posts’,’myFilter’);
And voila! It should be all sorted.
In case you aren’t sure how to find the category ID… go to the Categories section in your wordpress admin area (it’s under Posts). Hover your mouse over the category you want and notice in the status bar at the bottom of your browser there should be a url which ends/contains
tag_ID=5
in that case, your category ID is 5.
Leave a Reply