Have you ever wanted to exclude some specific categories from RSS feed on your WordPress site? Sometimes webmasters need to exclude some categories of posts from showing up within their website RSS feed. In this article, we will show you how to exclude specific categories from WordPress RSS feed.
1. First Easy Method – Plugin Approach
Using the plugin approach, what you need to do is to install and activate the Ultimate Category Excluder plugin. Upon activation, you need to visit Settings » Category Exclusion to configure plugin settings. The settings page of the plugin shows all categories on your WordPress blog with options to hide them from front page, RSS feeds, archive pages, and search results.
Once you are on the setting page, simply select the exclude from feed box next to the categories that you want to exclude from your RSS feed. Remember to click on the update button to save your changes. That’s all, posts filed under your selected categories will disappear from your WordPress RSS feed.
2. Coding Approach
This approach of preventing certain categories from showing up in your WordPress RSS feed involves making changes to your theme file. With this method, if you change the theme of your website you have to make sure the changes are carried over. In this method we will make a change in the functions.php
file. This files contains most of the methods and filter callbacks used to render your theme.
// Function to exclude certain categories from your WordPress RSS feed function exclude_category($query) { if ( $query->is_feed ) { $query->set('cat', '-5, -2, -3'); } return $query; } // add the filter hook add_filter('pre_get_posts', 'exclude_category');
The code simply excludes categories that match the given IDs. Simply replace the category IDs in the code with the IDs of categories that you want to exclude. To find the category ID if your post, visit the category page and view the URL of the category detail page to retrieve it. If you just want to exclude a single category, then change the code to use a single ID.