I’ve been playing around with backing up my tweets lately. At this point I’m using the Twitter Tools plugin to create a weekly digest. Since I created a Tumble-blog not to long ago to share social stuff like this I also wanted the tweets to go to tumblr. Part of this was just a way to clean up Tumblr and not create a new post everytime I tweet.
Now, having the tweets on the blog is mostly for me. I didn’t want to bombard people that are subscribed to the RSS feed with this weekly mashup of all my tweets, but still be able to have the RSS feed to send to Tumblr or for anybody that wants it.
This is what I ended up doing:
function tweetRSS123($query) {
if ($query->is_feed && !is_category()) {
$query->set(‘cat’,’-1′);
}
return $query;
}
add_filter(‘pre_get_posts’,’tweetRSS123′);
I got the idea somewhere on the web that I can’t remember. The big change that I made was !is_category()
. Which just says if it’s a category archive, don’t do anything. So it won’t remove the category from RSS if you actually take the RSS of that category.
So far it seems to be working. It’s hard to tell if it’s going to get along with the W3 Total Cache plugin, but I think I’m finally at a point where it’s going to work. It’s going to be really awesome if this works because I just spent an hour throwing together a plugin to send it to Tumblr just-in-case, but I’d really rather not use it.
If You Want to Use It
So there are two ways of using this snippet in your own theme. The way I’m doing it is to put this in the functions.php file for your theme, which gets treated just like a plugin except that it’s on a per-theme basis. This is where you can put any PHP function that are specific to your theme.
The other way would be to to add just a little bit more code and install it as a plugin, which is probably what I’ll be doing a little later when I get some free time to throw that together. The advantage of using something like this as a plugin instead of in your functions file is that it stays around for any theme that you use. If you forget to add this to the next theme you use though, your category is going to show up again.
You’ll have to remember to change the ‘-1’ value to the negative of the category ID that you want to exclude. The value is negative because we want to exclude it. If it were positive it would only include that category, which probably isn’t a good idea for your RSS feed.