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]

Worthwhile

So far, over 300 people have committed to participating in Project 52. It’s pretty safe to say that it’s exceeded everyone’s expectations. If ever there was a reason to write, Project 52’s quickly become one of them. If even a fraction of the participants stick with it, content on the web should see a marked improvement in 2010. I hope they’ll focus on quality and not just quantity. Committing to writing 52 posts is well and good, but if there’s little thought put into them, you might be better off not writing at all. After all, this is a personal challenge – one we should learn and grow from.

I know that by announcing my intentions with Project 52, I might be sabotaging myself, but my aim is to be as transparent as possible about what my plans are and what goals I hope to achieve through Project 52. And hopefully my transparency will help keep me more accountable. But transparency isn’t enough. I want my participation to mean something. That’s why I’d like to up the ante. For each post I write for Project 52, I’m going to be raising money for a charity. (Which one? Not sure yet, but I’ll announce between Christmas and New Years.)

If you like what I write, I’m hoping you’ll be encouraged to chip in something to help me reach a goal of raising $500. That breaks down to $9 a week. I know it can be done. And if my content’s good enough, it will be done.

What are your thoughts? Am I insane? If you dig the idea, got any charities you think would be worthy of support? (I’m thinking I might try to find a local charity to support, but would love any suggestions you might have.)