January 5, 2016

WordPress: How To Exclude Category From RSS Feed

If you need to exclude a specific category from your RSS feed, put the following code in your theme’s functions.php.

Go to Appearance | Editor | Theme Functions (functions.php)

// Excludes Category from RSS Feed
function exclude_catid_feed( $query ) {
if ( $query->is_feed ) {
$query->set( 'cat', '-1' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_catid_feed');

Replace -1 with the category ID number (keeping the preceding minus). To find the category ID number, go to Posts | Categories. Browse to the category you want to exclude and hover your mouse over it to reveal the link text on the bottom left of your web browser. The category ID number is just after &tag_ID=.

You can exclude multiple categories like this:

$query->set( 'cat', '-1, -2, -3' );

BONUS TIP!

You can use the same logic with slight modification to exclude a category from your home page.

// Excludes Category from Home Page
function exclude_catid_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-1' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_catid_home');

Sell Art Online

Get The Roo In Your Inbox

Receive The Roo Report only when new content is posted. We promise the Roo will be on his best behavior!

Please share your thoughts