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');
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');toadd_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
This doesn’t seem to be working for my feedburner feed. Is it cached, or should I see the feed entries change immediately?
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).
What’s odd is it’s working in mine… Not sure what might be different from my setup versus yours or Tammy’s… http://feeds.feedburner.com/cdharrison
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…
Whoops…should have replied instead of starting a new thread…sorry!
No worries. I assumed the same thing…
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.
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.
[...] Post Thumbnails in RSS feeds [...]
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?
Small question :)
will this work in Thesis without any modification? Please guide me!
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.