How To Exclude (or) Include Posts From Specific Category In WordPress RSS Feed

Categories in WordPress can be excluded either manually specifying category id in the Feed URL to exclude, it which can lead to SEO unfriendly URL formats or difficult to manage if there are many categories.Here’s a way you can exclude specific categories from your RSS Feed without the need for editing the FEED URL.wp-rss-exclude-category

Steps To Exclude Categories In WordPress Blog’s RSS Feed

  1. Open your theme’s functions.php ( which can be found in your Theme folder )
    and add this piece of code in it.

    function my_cat_exclude($query) {
    if ($query->is_feed) {
    $query->set(‘cat’,’-20,-21,-22′);
    }
    return $query;
    }
    add_filter(‘pre_get_posts’,’my_cat_exclude’);

  2. To include posts from just a single category in the RSS Feed
    Replace $query->set(‘cat’,’-20,-21,-22′); with $query->set(‘cat’,’20’); that’s just removing the “-” and placing the only category id of which you want the RSS Feed to display.
  3. You can replace the numeric’s in the 3rd line with the category id you want to exclude.Do not forget placing the “-“ Minus Sign before the value to exclude them from the RSS Feeds.

This function will strip the categories you define out of your RSS Feed without the need of adjusting your url.

SourceKriesi.at

Liked It ?? Share It 🙂Share on FacebookShare on StumbleUponTweet about this on TwitterShare on Google+Digg thisBuffer this page
Similar Post  How To Track Your Most Popular Posts Based On The Page Views From Your WordPress Admin

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *