WordPress Tip: Remove a Category from the WordPress RSS Feed

I recently setup The Events Calendar WordPress plugin on a few sites for work. The events are added as posts, so they show up in the WordPress RSS feed.

We didn’t want events showing in the RSS feed, this is the code I ended up with:

// Keep events out of RSS
add_filter('pre_get_posts', 'exclude_category_from_feed');
function exclude_category_from_feed($query) {
	if ($query->is_feed) {
		$query->set('cat','-'.get_cat_ID( 'Events' ));
	return $query;

Adding that bit of code to the functions.php file for your theme will prevent posts in the “Events” category from appearing in your RSS feed. You can obviously change “Events” to whatever category you want to exclude.
It can be extended too, not just limited to keeping a category out of the RSS feed. For example, to keep a category off the home page or archive pages, you can change this:

if ($query->is_feed) {

To this:

if ($query->is_archive || $query->is_home) {

That’s it! Hope you find it useful.


Well, now what?

Work with Me

I'm available for hire and always taking new clients, big and small. Got a project or an idea you'd like to discuss? Startup plan but no developer to make it happen? Just get in touch, I'd love to see if I can help you out!

Leave some Feedback

Got a question or some updated information releavant to this post? Please, leave a comment! The comments are a great way to get help, I read them all and reply to nearly every comment. Let's talk. 😀

Longren.io is proudly hosted by DigitalOcean


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.