Post Pic

WordPress hack: Display post thumbnail in your RSS feed

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

Jun 11 2010 19:32

Is this snippet including the alignment of all insertig images whithin the post?

Jun 12 2010 01:34

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.

Jun 24 2010 21:00

Hey but this is awesome! Is it working in 3.0?

Jul 01 2010 04:25

Hey but this is awesome! Is it working in 3.0?

Jul 04 2010 12:57

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.

Jul 13 2010 10:31

@Mukundan

The functions.php which is in your theme folder.

Jul 16 2010 17:03

@Mukundan Srinivasan
I think that they mean in the theme function file.

Jul 20 2010 16:47

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.

Aug 03 2010 16:50

Not working

Aug 05 2010 14:02

@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.

Aug 21 2010 03:08

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:

Leave a Comment

* Name, Email, Comment are Required