Excluding a blog category from your feed

June 25th, 2009 – 4 Comments

While I was working on a new system for my WordPress newsletter, a system that uses its own custom feed (skipping FeedBurner which caused errors last week), I had to figure out how to exclude a category from my blogs regular feed as well as my homepage and some other pages.

There’s a couple of ways to go about this, but what I decided to do was the following:

function mail_feed_query($query) {
	if ($query->is_home || $query->is_front_page) {
	return $query;

(120 is the category ID here)

This filters out the query from the home page and/or front page of your blog. Now you’ll need to do a bit of extra work to prevent it from showing up in category listings, everywhere you do a get_categories or wp_list_categories you just add &exclude=120 (where, again, 120 is the category ID).

So as of next week, my WordPress newsletter will be having its own unique articles again, as well as all the articles in the WordPress category. So, subscribe, like, now, so you don’t miss any of the goodness!

One of the things I intend to send out only to my newsletter subscribers is the new plugins I come across that I like or find useful, so if you don’t subscribe to the newsletter, you’re really missing out.

4 Responses to Excluding a blog category from your feed

  1. Esther Nowack
    By Esther Nowack on 29 June, 2009

    Why not not just using if($query->is_feed) ?

    • Oren
      By Oren on 30 June, 2009

      Haha, this guy got a point here.
      Waiting for Joost de Valk’s comment now :)

  2. Navin Poeran
    By Navin Poeran on 26 June, 2009

    @TheAnand: that’s also a nice way of sending newsletters, for free, without using aweber

  3. TheAnand
    By TheAnand on 25 June, 2009

    So, why not use feedburner and this script for a newsletter plugin avoiding the aweber?

Check out our must read articles about Analytics