Add Custom Values To Your WordPress RSS Feed

As most of you probably know, Script & Style was created by myself, David Walsh, and CSS-Tricks scribe Chris Coyier. We were both looking to create widgets for our website that would provide not only a link to the article submission page on Script & Style but also a direct link to the full article on the author’s domain. Since we were reading in the RSS feed to grab articles and links, we needed to add a custom XML key/value to the RSS feed so that we could retrieve the direct link URL. Here’s how we did it.
Hacking WordPress’ feed-atom.php File
WordPress creates two different feeds: a basic RSS feed and an Atom feed. Script & Style, like almost every other blog out there, uses FeedBurner to serve the syndication feed, and we chose to have FeedBurner use the Atom feed. In our experience, the Atom feed has been more stable and doesn’t cause problems in Google Reader like the basic RSS version does from time to time. Since we’re serving the Atom feed, we’ll need to modify the feed-atom.php file.
The code to complete this mission is short and sweet:
<entry> <author> <name><?php the_author() ?></name> <?php $author_url = get_the_author_url(); if ( !empty($author_url) ) : ?> <uri><?php the_author_url()?></uri> <?php endif; ?> </author> <!-- this is what we add --> <directurl><?php echo get_post_meta($post->ID,'Author Webpage',1); ?></directurl> <title type="<?php html_type_rss(); ?>"><![CDATA[<?php the_title_rss() ?>]]></title> <link rel="alternate" type="text/html" href="<?php the_permalink_rss() ?>" /> <!-- ...more fields below... -->
The direct URL is held in the database as a custom field called “direct_url.” Since there’s a relationship in the database between the article and the direct URL, all we need to do is use WordPress’ get_post_meta() function to retrieve the field we want.
The Result
Our feed at FeedBurner now looks like:

You can place the new XML key/value anywhere within the “<entry>” element.
That’s all you need to do to add custom key/values to your RSS feed. Now that you know how to do it, what would you use this for?
[...] over to Script & Style to check out the full [...]