How to add category exclusion to rss feed

I’m trying to exclude certain categories from the mydomain.com/feed

Researching online I came across this code:

<a href="https://wordpress.stackexchange.com/questions/21606/<?php bloginfo("url'); ?>/feed?cat=-3&cat=-12">Entries (RSS)</a>

Now the question is should I create a function (if yes what function to create) so I can exclude categories without having anyone to redirect to custom feed URLs

2 Answers
2

In your functions.php add:

function excludeFeedCats($query) {
    if ($query->is_feed) {
        $query->set('cat','-3, -12');
    }
return $query;
}

add_filter('pre_get_posts','excludeFeedCats');

Or use Simply Exclude for more flexibility.

Leave a Comment