You are viewing dblume

Previous Entry | Next Entry

pixelart
The RSS specification allows you to have an <image> element in the header of your RSS feed.  A long time ago, if you used Wordpress, you'd have to edit the wp-rss.php file and be very careful when you upgraded to new releases, or your change could be lost.

But if you use a modern version of Wordpress, you should take advantage of the do_action('commentsrss2_head') hooks* in the feed-rss... .php files.

Here's what you'd do: Add the following code to your theme's functions.php file:

function add_my_rss_image()
{
echo '<image><title>', bloginfo_rss('name'), '</title>';
echo '<url>', bloginfo_rss('stylesheet_directory'), '/images/button.gif</url>';
echo '<link>', bloginfo_rss('url'), '</link>';
echo '<width>88</width><height>31</height>';
echo '<description>Description of your blog.</description></image>';
}

add_action('rss2_head','add_my_rss_image');
add_action('rss_head','add_my_rss_image');
add_action('commentsrss2_head','add_my_rss_image');

Take care to actually put an image file in the path specified, and adjust the width and height accordingly.

Et, voila! Now your feeds have images, and they're forwards compatible with future versions of Wordpress. Oh, did I say future versions of Wordpress? Excuse me, I have to:

svn sw http://svn.automattic.com/wordpress/tags/2.6/

Blam! Upgraded. Sweet.

* Also rss2_head and rss_head, just so I cover the appropriate Google terms.

Comments

dblume
May. 14th, 2009 02:16 pm (UTC)
Re: Compatible?
Yes, it works in WP 2.7.1, and even through redirects through feedburner! See my family blog for an example. View source to convince yourself of my WP version. (The feed actually redirects to http://feeds2.feedburner.com/dlma/my, which retained the image tag.)
(Anonymous)
May. 14th, 2009 09:13 pm (UTC)
Re: Compatible?
Well, I'm perplexed. After my first comment, I removed the code from functions.php (didn't want to left behind code which didn't seem to work), but I left 'blog icons' plugin (which is basically just the same, with an admin interface) installed. I know it sounds silly, but since then, the image related code "appeared" in all 3 feeds over time, first in the Atom and rss feeds, then at last in the rss2 feed too. Now it's all fine. Maybe it was some kind of a caching issue, or something like that.

(By the way, do you know how to use feed favicons with rss? Atom can specify it, but rss doesn't. Somehow, most rss feeds I'm subscribed to show their favicons in the feed reader. Maybe the reader automatically pick up the site's regular favicon?)

greetz!
Charlie Brown