Exclude Categories From WordPress RSS Feeds
This guide shows you how to remove specific categories from your WordPress RSS feeds, so subscribers only see the content you want them to. You’ll need access to your WordPress admin dashboard and, depending on the method, your theme’s functions.php file or an FTP client. No coding experience is required for the plugin method.
What You’ll Need
- WordPress admin access (at least Editor role)
- For the code method: access to your theme’s functions.php file (via Appearance → Theme File Editor or FTP)
- Optional: a child theme to avoid losing changes on theme updates
Step-by-Step
Method 1: Using a Plugin (Recommended for Beginners)
- Log in to your WordPress admin dashboard.
- Go to Plugins → Add New.
- Search for “RSS feed exclude category” or “Category Excluder”. Choose a plugin with good ratings and active installs.
- Click Install Now, then Activate.
- After activation, find the plugin’s settings page (often under Settings → Reading or a dedicated menu item).
- Look for a section labeled “Exclude categories from feeds” or similar.
- Check the boxes next to the categories you want to exclude from your RSS feeds.
- Save your changes. Your main RSS feed (e.g., /feed/) will now skip those categories.
Method 2: Adding Code to functions.php
- Identify the category IDs you want to exclude. Go to Posts → Categories in your admin. Hover over a category name; the ID appears in the link (e.g.,
tag_ID=5). Note each ID. - Navigate to Appearance → Theme File Editor (or use FTP to edit your theme’s functions.php file).
- Add the following code snippet at the end of the file:
function exclude_category_from_feed($query) {
if ($query->is_feed) {
$query->set('cat', '-5,-7'); // Replace with your category IDs, negative means exclude
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category_from_feed');
- Replace
-5,-7with your actual category IDs, each prefixed with a minus sign and separated by commas. - Save the file. Test your feed by visiting
yourdomain.com/feed/in a browser or feed reader.
Method 3: Using a Custom Feed Template (Advanced)
- Copy your theme’s
feed.phporrss.phpfile to a child theme folder (if using a child theme). - Open the copied file in a text editor.
- Find the loop that outputs posts (usually
while (have_posts())). - Add a condition inside the loop to skip posts from certain categories:
<?php if (in_category(array(5,7))) continue; ?>
- Replace
5,7with your category IDs. - Save the file. This method gives you full control but requires more technical skill.
Common Mistakes
- Using positive IDs: In the code method, forgetting the minus sign before the ID will include only that category instead of excluding it.
- Editing the wrong file: Adding code to a theme file that gets overwritten on updates (like the main theme’s functions.php) can cause your changes to disappear.
- Not clearing cache: If you use a caching plugin, your feed may still show old content until the cache is cleared.
- Excluding categories from all feeds: The code method affects all feeds, including category-specific feeds. If you only want to exclude from the main feed, you need additional conditions.
Tips
- Always use a child theme for code modifications to prevent losing changes when the parent theme updates.
- Test your feed after making changes using a feed validator or a fresh browser incognito window.
- If you want to exclude multiple categories, list all IDs separated by commas with minus signs (e.g.,
-3,-8,-12). - Consider using a plugin if you’re not comfortable editing code; it’s simpler and safer.
- Remember that some feed readers cache content, so changes may not appear immediately for all subscribers.
Troubleshooting
- Feed still shows excluded categories: Clear any caching plugins (like W3 Total Cache or WP Super Cache) and your browser cache. Also check that you’ve saved the correct category IDs.
- Site error after adding code: If you see a white screen or error, you likely have a syntax error. Access your site via FTP and remove the code from functions.php, then re-add it carefully.
- Feed not loading at all: Check that your permalinks are set correctly (Settings → Permalinks → Save Changes). This often fixes feed issues.
- Code works but excludes too much: If you’re excluding categories from all feeds and you only wanted the main feed, add a condition to check if it’s the main feed:
if ($query->is_feed && $query->is_main_query()). - Plugin not working: Some plugins may conflict with caching or other plugins. Try deactivating other plugins to isolate the issue, or switch to the code method.
Frequently Asked Questions
Will this affect my sitemap or SEO?
No, this only affects RSS feeds. Your sitemap and search engine indexing remain unchanged. Excluding categories from feeds can actually improve user experience by delivering more relevant content.
Can I exclude categories from only the main feed, not category feeds?
Yes, with the code method you can add a condition to check if it’s the main feed. For example: if ($query->is_feed && $query->is_home()).
Does this work for custom post types?
The code method works for any post type, but you may need to modify the query to target specific post types. Plugins often have options for custom post types as well.
Will my subscribers see the change immediately?
Most feed readers check for updates periodically, so it may take some time for the change to propagate. Clearing caches can speed up the process.
Can I exclude categories from only certain feed formats (e.g., RSS2 but not Atom)?
Yes, with advanced code you can check the feed type using $query->is_feed('rss2') or similar. Most plugins don’t offer this level of control.
Is there a way to exclude categories without any coding?
Yes, using a plugin is the easiest way. Many plugins offer a checkbox interface to select categories to exclude from feeds.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.