wordpress: add the categories to a post rss title

I would like that the RSS entries titles be like this:

“this is the post title [category1, category4]”

Read More

In square brackets are listed the categories in which the post is filed.

I first modified the wp-feed.php file, but it’s dirty: every wordpress update will erase my changes. So i think i can do this via add_filter. I set it up like this, but i don’t know how i can have access to the post categories within my function. Any idea?

  function rssTitle_add_categories($title) {
        // how do i retrieve the category array ?
        $categories = join(', ', $category_array);
        $title = $title . '['.$categories.']';
        return $title;
    }
    add_filter('the_title_rss', 'rssTitle_add_categories');

Related posts

Leave a Reply

1 comment

  1. When the_title_rss filter functions are called (from the feed templates) you are inside a WordPress posts loop, and so the usual functions should work. You should be able to do something like this:

    $category_array = array_map(create_function('$category', 'return $category->name;'), get_the_category());
    $categories = join(', ', $category_array);
    $title = $title . '['.$categories.']';
    return $title;