How to add a thumbnail to your WordPress RSS feed

To make sure your RSS feed stands out in the crowd you can make it look a little bit nicer by adding a thumbnail to it. The following code should be placed in functions.php and it adds a thumbnail to both to the full RSS feed and also to the excerpt version if you choose to use that one.

function rss_post_thumbnail($content) {
	global $post;
	if(has_post_thumbnail($post->ID)) {
		if (get_option('rss_use_excerpt')){
			$content = '<p>'.get_the_post_thumbnail($post->ID).'</p>'.get_the_excerpt();
		}else{
			$content = '<p>'.get_the_post_thumbnail($post->ID).'</p>'.get_the_content();
		}
	}
	return $content;
}

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

About Fredrik Malmgren

Fredrik Malmgren is an entrepreneur, project manager and developer specialized in WordPress. Read more about me or get in contact with me. You can also find me on Twitter. (@fredrikmalmgren).
This entry was posted in Tutorials, WordPress and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>