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:

[sourcecode language=’php’]
function insertThumbnailRSS($content) {
$content = ‘

‘ .the_post_thumbnail(‘medium’). ‘

‘ .$content;
return $content;
}

add_filter(‘the_excerpt_rss’, ‘insertThumbnailRSS’);
add_filter(‘the_content_feed’, ‘insertThumbnailRSS’);
[/sourcecode]

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


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

[sourcecode language=’php’]
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’);
[/sourcecode]