Depending to your blog structure, it may be interesting to exclude some categories from your rss feeds. If you always wanted to find a clean way to do it, I’m pretty sure this recipe will make you happy.
Depending to your blog structure, it may be interesting to exclude some categories from your rss feeds. If you always wanted to find a clean way to do it, I’m pretty sure this recipe will make you happy.
Before starting to code, you'll have to know the numeric ID of the categories you want to exclude. If you don't know how to get the ID of a particular category, just read this recipe.
Once you have the ID of the categories you want to exclude from your rss feed, open the functions.php file from your theme. If your theme doesn't have a functions.php file, create one.
Paste the following code in it:
function myFilter($query) {
if ($query->is_feed) {
$query->set('cat','-5'); //Don't forget to change the category ID =^o^=
}
return $query;
}
add_filter('pre_get_posts','myFilter');
Credit goes to Scott Jangro for this awesome recipe!
26 Responses
That’s pretty cool, especially if you have a section where you write things unrelated to your blog which might put your regular readers off
I love this idea the more I think about it. Thank you so much!
You’re welcome, guys! Glad you enjoyed this recipe.
I like this idea. never heard of this before
Thanks. This tip is small but useful :).
Good idea, great note
Thank you…
this is it. been wondering how to do that. thanks!
good one, but is there a way to have a RSS feed of a given category and all it’s children.. shall I remove the minus, and have alll the categories like
$query->set(’cat’,'5,6,7′);
or is there a way to have the children categories listed automatically?
thank you in advance
@Fromtheold, agreed i post some posts on my blog which are sometimes off topic and put off the readers. Excluding those categories would help.
Thanks for the tip.
Very good! But it seems not work Wordpress2.7. I do not understand:-(
Trackbacks: