
Introduced in WordPress 2.9, get_the_post_thumbnail() allow you to display a thumbnail in your posts. But what about displaying post thumbnails in RSS feeds? Just read this recipe to know how to do.

Introduced in WordPress 2.9, get_the_post_thumbnail() allow you to display a thumbnail in your posts. But what about displaying post thumbnails in RSS feeds? Just read this recipe to know how to do.
Simply paste the following code in your functions.php file. The post thumbnail should be visible once you saved the file.
function diw_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<div>' . get_the_post_thumbnail($post->ID) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
add_filter('the_content_feed', 'diw_post_thumbnail_feeds');
Thanks to Jeff Starr for this great tip!
12 Responses
Is this snippet including the alignment of all insertig images whithin the post?
Thanks very much. Works great. One thing that isn’t included is any photo wrapping, which would be cool, but not essential. So the photo sits atop the text in the feed.
Hey but this is awesome! Is it working in 3.0?
Hey but this is awesome! Is it working in 3.0?
I have a doubt in most of the recipes they say functions.php I want to know whether it is the functions.php in theme folder or the one present in wp-includes folder.
@Mukundan
The functions.php which is in your theme folder.
@Mukundan Srinivasan
I think that they mean in the theme function file.
On this site—I do believe they will always refer to your theme’s functions.php file. One of the advantages to this is to allow for the portability of these functions from one theme to another without editing the actual theme itself. If you didn’t already understand that.
Not working
@Kartik
Are you sure your posts have thumbnail? I think that this code will not create one, just take it from the posts thumbnail and show it in the feed.
AWESOME!!! I’ve messed around with so many shaky RSS image plugins (even the google feedburner system can be flakey), but this is EXACTLY what I was looking for. My posts contain ONLY post thumbnails using the new WP3 feature. So the feed only says ‘read more’ if I don’t have post thumbnails in it.
Your little piece of code completes my ‘proof of concept’ for this site, thank you.
Trackbacks: