WordPress

Exclude Categories From RSS Feed In WordPress

In a previous snippet you would of seen that you can change the WordPress have_posts() method to exclude a category from the index page but you can also exclude a category from the RSS feed.

Below is a snippet you need to add to your functions.php page which will run before the get posts method. It will check to see if the request is from the RSS feed if so then it will exclude a category from your RSS feed.

// Custom Feed Query
function customFeedquery($query) {
        $categoryId = 1; // Change ID to the excluded ID

	if(is_feed()) {
		$query->set('cat','-'.$categoryId); 
		return $query;
	}
}
add_filter('pre_get_posts', 'customFeedquery');
Back to top ^

Join Paulund

  • Get access to 100s of premium tutorials and downloadable content
  • Members content consists of Premium WordPress plugins, CSS packages, jQuery packages, tutorial demo files and templates for 100s of web development tutorials
  • In-depth development tutorials
  • Priority tutorial requests
  • Priority email development support
  • No ads

Here at Paulund you'll find Web Development tutorials and snippets focusing mainly on PHP, WordPress and CSS. Members will get access to premium tutorials that go into more detail about development with these languages. You will also get access to downloadable premium content based on the tutorial.

Join Paulund

Leave a Reply

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