Show Featured ImagesShow Featured Images in RSS Feed and Feedburner in RSS Feed and Feedburner

add thumbnails to RSS Feed


I want to tell you about “Adding thumbnails to RSS feed” or better to say “Show featured images in RSS feed“. This method will work with your WordPress RSS feed and with Feedburner RSS feed. As you know, you can add a featured image to your blog post and this image will be displayed in a specific place, somewhere near to your blog post excerpt on the home page of your blog (the place and size depends on your template).
By default this thumbnails or featured images will not be shown in your RSS feed, but you can fix that by adding some piece of code into your functions.php file.

Why to Show Featured Images in RSS Feed

To Make Your RSS Feed Look Better

By displaying featured images or post thumbnails in your RSS feed (or Feedburner feed) you will make it more accurate, beautiful and more informative, especially if you are showing just excerpts of your posts. This will improve web design of your blog. Text is boring, give some images to your subscribers. As an example you can visit My RSS Feed, Don’t forget to subscribe! :)
And this is how my RSS feed looks in RSS reader:
add thumbnails to RSS Feed

Get More Traffic from Your RSS Feed

My statistics shows that subscribers are coming from RSS readers more often if your post have some images. That trick is working on my blogs, maybe it will work on yours.

How to Show Featured Images in RSS Feed

To output your featured images in your RSS feed, you need to add some code to your functions.php file. Go to your WordPress Dashboard / Appearance / Editor, choose functions.php and add this code at the end in new line (make a copy of your functions.php file… just in case).

1
2
3
4
5
6
7
8
9
10
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float:left; margin:0 15px 15px 0;' ) ) . '' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
Save your changes.
The example of inserting the code to functions.php file:
Show Featured Images in RSS Feed

Styling Your Featured Images in RSS Feed

Size of the Featured Images

This hack will add featured image with “thumbnail” size and it will be shown from the left side of the post excerpt, but you can change it. In the this line: . get_the_post_thumbnail( $post->ID, 'thumbnail' change the word ‘thumbnail‘ to ‘medium‘, ‘large‘ or ‘full‘ (‘full’ will show the original size of your thumbnail image, I’m using full images). It will be a good idea to delete floating if you will change the size to ‘large‘ or ‘full‘, because images will not fit to your text. So read my next tip.

Style of the Featured Images

By default this hack will put images to the left side of the excerpt, but you can change the float side in this line: 'float:left; margin:0 15px 15px 0;'. Change that line to this one (with quotes): 'float:right; margin:0 20px 20px 20px;'.
To remove the floating (for large and full sized images) and put your image on the top of the post, just use this code instead of the previous one:

1
2
3
4
5
6
7
8
9
10
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');

“I Did Everything Like You Said, But Feadburner Doesn’t Show Featured Images!”

This hack is working (for WordPress 2.9 and later ) but not immediately, because Feedburner needs to update your changes first. You need to wait 24 hours or write a new post to force Feedburner to update your feed.
I hope that this WordPress hack was useful for you. Just leave a comment ff you have any questions about adding thumbnail images to your RSS feed and Feedburner.

No comments: