Add WordPress Post Thumbnails to your RSS Feed

RSS_feed

I was working on some minor updates on the Notes From a Gluten-Free Kitchen website yesterday when I noticed that the ‘Post Thumbnails‘ were not being output in the RSS feed. This definitely got me scratching my noggin’ a bit. ‘Post Thumbnails’ or ‘Featured Image’ are now a core feature of WordPress. First introduced in WP 2.9 the ‘Post Thumbnails’ have solidified as a key feature and are widely used by bloggers and theme developers alike. So, the fact that they weren’t output by default into the RSS feed was strange to me.

After a little research, sure enough this is not included in WordPress core yet, even though it should be. So here is how I was able to get the Featured Images to show up in the RSS and Feedburner feeds.

Modify your themes’s Functions.php file

All you need to do is add some code to your themes functions.php file. Make sure you are editing the functions.php file within your theme, not within the wp-admin directory. I prefer to always add new functions to the end of the file with a nice comment header to identify what the function does. Also make sure that you place this code right before the ending ?>

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’);

Control the Size of the Image

This code will add your post’s featured image with “thumbnail” size and it will be shown from the left side of the post excerpt, but like everthing with code you can modify it how ever you’d like. In the this line: . get_the_post_thumbnail( $post->ID, 'thumbnail' change the word ‘thumbnail‘ to ‘medium‘, ‘large‘ or ‘full‘. I ended up using the ‘large’ size for my feed.

Hope this helps. Maybe WordPress will add this feature by default in the future, however after a quick scan of the WordPress Trac I don’t see it listed anywhere.

 

8 Comments

  1. I just tried doing this, and now I cannot get into my website. This error is coming up!

    Parse error: syntax error, unexpected ‘:’, expecting ‘)’ in /home/awieske/wieskedesign.com/wp-content/themes/delight/functions.php on line 24

    • Hi Alyssa,

      I’d be happy to help you trouble-shoot this. Have you removed the code from the functions.php file and re-uploaded the file?
      Feel free to email me a derekshirk [at] brewhousepdx.com

  2. I’m not sure how I would remove the code, I cannot get into the admin
    panel.
    My website is http://www.wieskedesign.com
    And here is the link to my admin panel, but it doesn’t open.
    http://www.wieskedesign.com/wp-admin

    Would really appreciate your help!!!!!

    I tried emailing this to you, but it said it failed. You can email me back: alyssa.wieske@gmail.com
    Thanks!

    • Alright. I’m sending you an email right now.

  3. Thanks so much for fixing the problem so quickly! I really appreciate it!!

  4. Hi Derek
    Tried inserting the code in my functions file but I had a similar problem to Alyssa – I can’t do anything from my dashboard admin panel. I can get to the home page of the dashboard, but anything I click on from there gives me a blank page so I can’t get back to the functions file to remove the code. Also nothing comes up when I type in the website address.

    Fortunately I tried the code on a test site only, but I do need to get back into that. Please help this non-techie! The site is http://www.mydytest.com/wp-admin/.

    Tried emailing derekshirk [at] brewhousepdx.com but that failed. Email me at dyounglao [at] live.com. THanks!

  5. I’d really appreciate some help here, Derek. I can’t do anything from my admin panel since adding your code and so I can’t remove it. The problem site is http://mydytest.com and you can email me at dyounglao [at] live.com for my login info. Thanks

  6. any idea how to parse the image back out again using simplepie? can’t seem to access it with get_thumbnail()
    thnx!
    -jennyb

Comments make the world go round...

Leave a Comment