How to add XML elements to your WordPress RSS feed

A while back, I shared a little way of customising the individual title of each item in your WordPress feed. That was based on filtering the existing title, and prepending the requisite content, which in that example was the post type (Gallery, Video, etc.).

I’m now using a variant of that same technique in The Stage’s new RSS feeds. News, Features, and Columns and their respective subcategories are all implemented using WordPress’s built-in categories system. The relevant category (News, Arts 2.0, Obituaries, etc.) precedes the relevant article’s headline. It’s not an ideal solution: if you grab a category feed, e.g., the RSS feed for Shenton’s View, every article will still contain the category name, even though it’s implicit from the context in which you’re requesting the feed.

Recently I’ve had an additional need, though: to add additional XML elements to an RSS feed in a way that gives additional flexibility to custom clients, but doesn’t break any feed readers.

Continue reading “How to add XML elements to your WordPress RSS feed”

How to label non-standard post formats in your WordPress 3 RSS feed

In an attempt to try out post formats in WordPress 3, I flagged my last short post as an ‘aside’. It turns out that, in WordPress’s default “Twenty Eleven” template at least, there’s not too much difference between a ‘standard’ post and an ‘aside’ once you get to the individual page, although they are rendered differently on the site’s home page.

That’s a shortcoming in Twenty Eleven, to my mind. I’m in the process of constructing a WP 3.2-compatible template for work, and while we won’t be supporting all of WordPress’s post formats, we’ll need to format entry detail pages, and flag up entries on index pages, depending on which format we use.

For RSS feeds, Tweets, etc., I may want to indicate the type of post format so that readers know what to expect. For example, if an entry has been defined as a Gallery style post format, I may want the RSS reader to display:

Gallery: A selection of pictures

Modifying WordPress’s RSS feeds are slightly trickier than the web pages, as they’re not defined within the theme folder. However, WordPress’s add_filter can come in very useful, as illustrated in this sample code:

Adding this function to my theme’s functions.php means that last week’s aside now shows up in my RSS feed as:

Aside: Park Avenue Cat, Arts Theatre

As far as I’m concerned, this is a temporary fix. It doesn’t do the same for automatically sent tweets going via the plugin I use for that purpose, and there are other places in a template where you’d want to use a similar technique. But it’s a start, and if you’re out there scratching your head and wondering how to tweak your RSS output, hopefully this may give you some clues.