Improving RSS output from WordPress

The default syndication output from WordPress is okay, but does leave room for improvement – even though it “defaults” to RSS 2.0, there’s RSS 1.0 hidden behind the scenes.

The first order of action is to fix the default page template to point to the RDF/XML output instead of RSS 2.0. In the file /index.php there are link elements in the head section of the HTML output, switching to RSS 1.0 is quite easy, simply change the RSS 2.0 line to the following (and remove the link to the 0.92 version):

<link rel="alternate" type="application/rdf+xml" title="RSS 1.0" href="<?php bloginfo('rdf_url'); ?>" />

In the meta section there is also a couple of links, one for RSS 2.0 that will be replaced by a link to RSS 1.0, and one for comments that is just dropped (an RDF/XML version may be added at a later date):

<li><a href="<?php bloginfo('rdf_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>"><?php _e('<abbr title="RDF Site Summary">RSS</abbr> 1.0'); ?></a></li>

Now to the actual content of the RSS file: The default template includes, for each post, a dc:creator property that looks like this:

<dc:creator>mortenf (mailto:mort&#101;n&#64;&#119;as&#97;b.dk)</dc:creator>

That’s not terribly helpful for the Semantic Web, so I’ve hacked the template wp-rdf.php to include the following FOAF structure instead:

<foaf:maker>
  <foaf:Person>
    <foaf:name><?php the_author_firstname(); print ' '; the_author_lastname() ?></foaf:name>
    <foaf:nick><?php the_author_login() ?></foaf:nick>
    <foaf:mbox_sha1sum><?php print(bin2hex(mhash(MHASH_SHA1,'mailto:'.$authordata->user_email))) ?></foaf:mbox_sha1sum>
    <foaf:weblog rdf:resource="<?php bloginfo_rss('url') ?>"/>
  </foaf:Person>
</foaf:maker>

In addition to this improvement, the indication of categories could also use a little tune-up. The default output shows categories through the use of dc:subject, which is quite allright but somewhat too vague – how could anyone know that my category SemWeb/FOAF is essentially the same as Danny AyersKnowledge/FOAF category? To make up for this, it is possible to use the Description field in WordPress’ category system to assign a URI to each (or some) of the categories, and then generate appropriate statements by adding two lines to the the_category_rss template function in /wp-includes/template-functions-category.php:

if(preg_match('|^w+:.+/|',$category->category_description))
    $the_list .= '<foaf:topic rdf:parseType="Resource"><dc:title>'.$category->cat_name.'</dc:title><foaf:page rdf:resource="'.$category->category_description.'"/></foaf:topic>';

The results of these tweakings should show up nicely in the RSS feed – check it out here.

8 thoughts on “Improving RSS output from WordPress

  1. Pingback: Binary Relations
  2. Pingback: Internet Alchemy
  3. Hi Morten, your current RSS doesn’t seem to use the code given here. The categories in your current RSS use foaf:made where you show foaf:page above. Wonder if this is a typo?

  4. Hi Ian,

    You’re right, this is not the code that’s being used now. The current “enhancements” in the RSS feed is generated by the FOAF output plugin which does in fact include a typo re made/page, will fix in next release, due out later today, thanks for the catch…

  5. Hello Morten … I just want RSS 1.0 output to join the meta list on my template. So I implemented the first two lines of your solution in my default template without deleting RSS2 or 0.9. Whilst I certainly get a link to wp-rdf in my meta section when I attempt to view the RSS this is treated as an attempted download of the file with no RSS apparently being generated. Any ideas. Many thanks …

Comments are closed.