Prepend labels to RSS item title by category

I’ve been rethinking this blog’s design lately & one of the problems with my current setup is that, while I’ve styled different kinds of posts differently here on the blog, they’ve all still looked the same in the RSS feed. Seeing as I read most of the blogs I follow via RSS myself, this is something I wanted to take care of. The easiest option was just to prepend “link:” or “tweet:” to the title of each item when that item is in one of those two categories.

Turns out, that’s actually really easy to do using WordPress' ‘the_title_rss’ filter and throwing together a simple plugin. Here’s what I did: create a php file in WordPress' plugin directory, add the necessarily header information, and then add this in the body of the php file:

<?php
function prepend_to_title_rss($itemTitle)
{
    if (in_category('links'))           // Category name
    {
        $addThis .= 'link: ';           // Prepend to RSS title
        $itemTitle = $addThis.$itemTitle;
    }
    elseif (in_category('tweets'))      // Another category name
    {
        $addThis .= 'tweet: ';          // Prepend to RSS title
        $itemTitle = $addThis.$itemTitle;
    }
    echo $itemTitle;
}

add_filter('the_title_rss', 'prepend_to_title_rss');
?>

Just change the category names & the $addThis values.

Friday, August 22, 2008