Post Thumbnails in RSS feeds

Standard

the_post_thumbnail is one of my favorite additions to WordPress 2.9, but I recently ran into a problem… the images I had set as my post thumbnails weren’t being included in my RSS feed. Assuming you’ve already added support for thumbnails to your theme, you should be able to add this snippet to your theme’s functions.php file to display them along with the rest of your feed content:

function insertThumbnailRSS($content) {
    $content = '<p>' .the_post_thumbnail('medium'). '</p>' .$content;  
    return $content;  
}

add_filter('the_excerpt_rss', 'insertThumbnailRSS');  
add_filter('the_content_feed', 'insertThumbnailRSS');

Thanks to Dougal Campbell for pointing me in the right direction!


Thanks to Sébastien Méric here’s an event better approach:

function insertThumbnailRSS($content) {
   global $post;
   if ( has_post_thumbnail( $post->ID ) ){
       $content = '<p>' . get_the_post_thumbnail( $post->ID, 'medium' ) . '</p>' . $content;
   }
   return $content;
}

add_filter('the_excerpt_rss', 'insertThumbnailRSS');
add_filter('the_content_feed', 'insertThumbnailRSS');

23 thoughts on “Post Thumbnails in RSS feeds

  1. hi,

    thanx for the idea :)

    but, as i tried your tip, some thing went wrong…
    the_post_thumbnail() echoes get_the_post_thumbnail().
    also, as i just read the new features for wp2.9 (http://codex.wordpress.org/Version_2.9) 15 min ago (!), it’s said that the_content_rss is now deprecated in favor of the_content_feed.

    so this has worked for me :

    function insertThumbnailRSS($content) {
    global $post;
    if ( has_post_thumbnail( $post->ID ) ){
    $content = '' . get_the_post_thumbnail( $post->ID, 'medium' ) . '' . $content;
    }
    return $content;
    }

    add_filter('the_excerpt_rss', 'insertThumbnailRSS');
    add_filter('the_content_feed', 'insertThumbnailRSS');

    i hope that could help a bit :)

    seb

    • Méric, Thanks for that. I tried it and it ended up breaking my feed. I’m running WordPress 2.9 Release Candidate 1.

      Changing add_filter('the_content_rss', 'insertThumbnailRSS'); to add_filter('the_content_feed', 'insertThumbnailRSS'); did work fine. I’ll update my example up top.

      Could email me your code snippet just in case? chris@cdharrison.com

  2. This doesn’t seem to be working for my feedburner feed. Is it cached, or should I see the feed entries change immediately?

  3. drokkon

    Works great for me on my local RSS, but like Tammy, I have yet to see the thumbnails show up on the Feedburner version (that’s really what I’m going for, to entice more clicks from my email readers).

  4. drokkon

    Strange. I always had my feedburner feed pointed to domain.com/feed/. However, the thumbnails WERE showing up in domain.com/feed/rss2/, so I just redirected feedburner to that URL, and now I’ve got the thumbnails. Troubling, because this whole time I assumed that the default /feed/ address WAS the RSS2 address…

  5. Thanks, it seems to be working.. This is the only place I found that addresses this issue, do other people not have it? *shrug*

    • I’m guessing it just hasn’t come up yet for a lot of people. It’s necessity became apparent when a client asked why the thumbnails being used by their posts weren’t being displayed in the feed. I think 1) a majority of WordPress users are using themes that haven’t added support for post thumbnails yet; 2) they have post thumbnails but don’t realize they are there; or, 3) they have post thumbnails and they use them, but didn’t realize they’re not included in RSS feeds.

  6. Great function!

    I am working on writing an image plugin, that I plan to release as GPL.

    Do you mind if I include this capability?

    Thanks!

    • Do I mind? Absolutely not. Anything that enables users to get this functionality without having to “get their hands” dirty would be a great thing.

  7. just implemented code and worked great! – looked for this solution for days – your site is the only one referencing this! Do you know how to align the thumb image left – so the text is inline with the image?

    • I think it would require adding it to your custom_functions.php. I only have limited experience with Thesis so I’m not sure I have a better answer than that at the moment.

  8. What if i need to show not only post thumbnails, but thumbs from custom fields and thumbs, that takes from media library after upload? I show it on my homepage this way

    But how implement in in rss?

    • Sorry for the delay in responding. Didn’t realize the comment was stuck in my Approve queue. I’m not sure, to be honest. I’m sure something could be written that would scan a Post for custom fields and attached media, but that’s outside of my skill-level at the moment. This was more about solving a problem with a new, native feature.

  9. Thanks Chris! I added post thumbnails to a theme and didn’t realize for a month that that the images weren’t showing up in the RSS feed ;-) Since the site is pretty much all images the feed was mostly blank. This worked perfectly.

    And it should work in Thesis if it’s added to custom functions – I haven’t done it but there is no reason why it wouldn’t.

  10. Hey, do you need to call the “insertThumbnailRSS” from another PHP? I’ve just put it in the functions.php one and nothing seems to happen…

  11. Pingback: Anonymous

Comments are closed.