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!