How To: Add a Post Thumbnail to an RSS Feed in WordPress

Have you ever needed to add the WordPress post thumbnail to an existing RSS feed? The below code will add a new element named <thumb> to your RSS feed. This element will contain a link to the post thumbnail as set in WordPress:

function ThumbRSS() {
	global $post;
	if ( has_post_thumbnail( $post->ID ) ) { 
		$thumbpic = get_the_post_thumbnail( $post->ID, 'thumbnail' ); 
	}
	
	echo '<thumb>'.$thumbpic.'</thumb>';
}

add_filter('rss_item', 'ThumbRSS');

Keep in mind using this technique will devalidate your RSS feed as the <thumb> element is not a part of the RSS specification. An alternate approach is to attach the post thumbnail to the beginning of your post content in your RSS feed. Below is an example using this method:

function ThumbRSS($content) {
   global $post;
   if ( has_post_thumbnail( $post->ID ) ){
       $content = '<p>' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '</p>' . $content;
   }
   return $content;
}

add_filter('the_excerpt_rss', 'ThumbRSS');
add_filter('the_content_feed', 'ThumbRSS');

Just drop either code example in your themes functions.php file for this to work. Pretty easy huh? Now you can easily include post thumbnails in your WordPress RSS feeds!

My Interview on the WordPress Weekly Podcast

Yesterday I had the pleasure of being interviewed by Jeff Chandler on the WordPress Weekly Podcast! It was great to be back on the show, even though the spotlight was on me this time. I’ve been participating on the WP Weekly podcast since the start (episode 1) so it was fun to reminisce a bit about how we both started into WordPress and how the podcast came to be.

Hal Stern also joined in at the beginning of the show to discuss our new book, Professional WordPress. Jeff and I also discussed many different topics including the challenges of running a business around open source, secret projects in the works, my thoughts on WordPress and how it compares to other open source CMS solutions, and much more! Be sure to check out the episode and let me know how I did!