Weblog, Wordpress, RSS

In the course of trying to tidy up cloudsoup a little I noticed that my RSS feeds’ contents weren’t formatted nicely in my News Reader - SharpReader. Not a Sharpreader problem it turns out, but (I think) a Wordpress problem.

My RSS description node content is being converted to safe tokens by output-escaping, rather than being wrapped in a CDATA tag. According to the RSS spec, encoding HTML within a CDATA Section in the description is perfectly permissable but there seems to be no option in the default Wordpress wp-rss2.php file, the PHP code that does the job of creating the RSS - no parameter that can be passed in the Wordpress function.

If you choose to syndicate the full post of your weblog post in your RSS feed then the RSS is built like this:

<description>
<?php the_excerpt_rss(get_settings(’rss_excerpt_length’), 0) ;>
</description>
<content:encoded>
<![CDATA[<?php the_content('’, 0, ‘’) ?>]]>
</content:encoded>

whereas if you choose only an excerpt, the RSS gets built like so:

<description>
<?php the_excerpt_rss(get_settings(’rss_excerpt_length’), 0) ?>
</description>

and the function the_excerpt_rss doesn’ t take a parameter that stops all encoding transformations.

The unwanted upshot of this is that, for example, a post I’d like to see looking like this in my RSS:

  • CrashBonsai » toy cars and miniature trees collide
  • BBC NEWS | Wales | Royal seal of approval for Wales Millenium Centre » That’s a relief then
  • Sushi Eating HOWTO »…

actually looks lke this:

CrashBonsai » toy cars and miniature trees collide BBC NEWS | Wales | Royal seal of approval for Wales Millenium Centre » That’s a relief then Sushi Eating HOWTO »…

Which is not good. The WordPress Wiki’s entry on the_excerpt_rss says that I should be able to impose minimal filtering so I think my problem is being caused by the fact that I don’t have an excerpt, only a post body to most posts - and Wordpress is doing another conversion on my behalf.

I could always replace the function, the_excerpt_rss with the_excerpt - which isn’t encoded by default. But when I try that, although the content is not tokenised, I still can’t see my del.icio.us lists properly.

The correct, Wordpress solution would be to create a Wordpress plugin. Until I do that, this is a quick-and-dirty way. The temporary solution is to make a small change to the file wp-rss2.php, amending

<description>
<?php the_excerpt_rss(get_settings(’rss_excerpt_length’), 0) ?>
</description>

to

<description>
<![CDATA[<?php the_excerpt_rss(get_settings(’rss_excerpt_length’), 3) ?>]]>
</description>

and then to make another amendment to the function get_the_excerpt in the file template-functions-post.php. Simply comment out the line :

$output = strip_tags($output);

That seems to be working now for my RSS feed (which, incidentally, I’ve burned through FeedBurner). I’ll need to test it a little first to make sure everything’s still working properly.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*