How to add an image to your WordPress feed

This is directly from the page David – Adding the image tag to WordPress’s rss headers

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('url'), '/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>';


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

Blam! Upgraded. Sweet.

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

Leave a comment