What the heck is going on, you ask? Say hello to Tersus.

Bare bones? You got it. Tersus is an achingly simple WordPress theme without all the usual cruft.

Super Ginormous

This is the personal site/blog/experiment of Chris Harrison, a web designer living, working and playing in Augusta, GA.

|

Wednesday, December 16th, 2009

Post Thumbnails in RSS feeds

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');

This item was posted by Chris Harrison.

Tags:

Categories:

You can follow comments on this item via the RSS 2.0feed.

Comments are closed.

23 comments on “Post Thumbnails in RSS feeds”

  1. Posted by Méric Sébastien on Wednesday, December 16th, 2009.

    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

    • Posted by Chris Harrison on Wednesday, December 16th, 2009.

      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. Posted by Tammy Hart on Saturday, January 2nd, 2010.

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

  3. Posted by drokkon on Friday, January 15th, 2010.

    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. Posted by drokkon on Friday, January 15th, 2010.

    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. Posted by Ernie on Thursday, January 28th, 2010.

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

    • Posted by Chris Harrison on Thursday, January 28th, 2010.

      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. Posted by Tom Lany on Friday, February 5th, 2010.

    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!

    • Posted by Chris Harrison on Saturday, February 6th, 2010.

      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. Posted by dawn on Friday, February 19th, 2010.

    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?

  8. Posted by Nitin on Tuesday, March 16th, 2010.

    Small question :)

    will this work in Thesis without any modification? Please guide me!

    • Posted by Chris Harrison on Tuesday, March 16th, 2010.

      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.

  9. Posted by brainsolid on Wednesday, April 14th, 2010.

    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?

    • Posted by Chris Harrison on Tuesday, May 4th, 2010.

      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.

  10. Posted by Kim Woodbridge on Sunday, April 25th, 2010.

    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.

  11. Posted by sbiker on Saturday, May 15th, 2010.

    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…

  12. Posted by Chris on Friday, July 30th, 2010.

    So how would I do it if I don’t want it in the description and want it in an image tag?
    like at http://www.w3schools.com/rss/rss_tag_image.asp