WordPress: Add featured image to RSS feed

I’m a firm believer in minimising the amount of plugins a WordPress site uses and instead making code changes to get what you need. This removes the overall bloat of a site and makes things far easier to manage. From time to time I come across useful plugins, but instead of using them I work out the quickest way to achieve the same goal by coding it myself. Here’s a simple function I use to show a post’s featured image in the RSS feed (something WordPress does not do by default):

add_filter( 'the_content', 'featured_image_in_feed' );
function featured_image_in_feed( $content ) {
global $post;
if( is_feed() ) {
if ( has_post_thumbnail( $post->ID ) ){
$output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
$content = $output . $content;
return $content;

view raw


hosted with ❤ by GitHub

Just paste that code into your theme’s functions.php file and you’re good to go. You can obviously modify the style attribute to have it display however you wish, as well as the image size (set to ‘medium’ in this example) – the options for this are: thumb, thumbnail, medium, large & post-thumbnail.

59 Thoughts

    1. It was really a headache to see the RSS-to-email campaigns without no images because the RSS feed did not have the necessary tag to pull images from. Anyway, changed the functions.php file and now MailChimp can pull the required components and now the emails look beautiful.

      However, still the images in RSS feed look really big and wish to resize them to a suitable size. Needs to search more and find a solution for this.

  1. Hi,
    I did what you said in my wordpress blog and it did not work. There are lots of people looking for this feature and I do not want to install a plugin at all.

    I have two function files functions.php and theme-functions.php and I tried already in both.

    I am not seeing the images in your feed neither… Hope you can enlighten me


    1. Hi Javi,

      The code itself should work fine if you paste it into your theme’s functions.php file in the root folder for the theme. If it’s not working for you then make sure you are setting your featured image correctly (using the WP featured image and not your theme’s custom image setting).

      Since changing some things on my site I have removed the images from my feed – I’ll put them back sometime, but for now you won’t see them there.


  2. I have been trying to give an image to RSS I include on my WP blog. However, it always results in failure. your recent writing I am reading now works well, unfortunately I am not so familiar with coding or something similar. could you please provide me with something simpler instead?

    1. I have tested this code again in the latest version of WordPress and it works correctly as it is now – I can’t really provide you with anything simpler as this is about as simple as you can get for this kind of thing.

  3. I pasted the code into my function.php but when i view my RSS source, i dont see any images to my items. I’m using the WP featured image function of WP (running latest version); What am i doing wrong?

  4. Thanks for this Hugh – needed it for a cartoon blog I am running and relieved at the thought of not having to add in another plugin! I’m curious to know if there is any way of overlaying some message on the thumbnail in the feed (e.g. click on cartoon to view full image on the site) – or even if I could insert the message under the featured image in the feed itself it would be great… any suggestions please?

    Thanks again!

    1. Hi Pratish – the $output variable merely contains the HTML of the tag, so all you would need to do is add more text/HTML onto the beginning or end of that variable and it will show up as you have defined it. You have the global $post variable available so you can use that to display any dynamic post data you want at this point.

      1. Thanks for the reply Hugh – sorry, I’m bit of a newbie so need a bit more help on this please. I’ve also been trying to get the thumbnail in the RSS feed to link to the actual post (so RSS readers can click on the image to see the full cartoon on the website). I’m honestly not sure how to tailor these two lines to include the “a href” to achieve this:

        $output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 10px 10px 0;' ) );
        $content = $output . $content;

        1. Thanks for the Hugh – I tried it out and it crashed my feed… managed to fix it though :). The working code, including the link to the post from the thumbnail should read:

          $output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:left; margin:0 10px 10px 0;' ) );
          $output = 'ID ) . '">' . $output . '';
          $content = $output . $content;

        2. Oops sorry I thought using the code tags would allow me to write the href too – I can send you the code if you’d like to update it. Basically the rel=”nofollow” bit in your pastebin thing was in the wrong place so it didn’t work.

  5. Hi Hugh …

    I’ve added the code to my php and it still doesn’t work. I have added all kinds of suggestions to the code, yours had a slight variation that I was hoping would fix the problem. I am SO baffled because I can’t think of anything else to do.
    I don’t know if it’s something in my overall Feedburner that isn’t picking it up?

    I would really love your expertise. I can send you anything you need to look at it.

    Thank you so much.

    1. Is there a logical progression from this snippet that would put the featured image in its own tag in the RSS feed (outside of the content). It would be nice to lead with the featured image, then display the title, date, then content.

      Any thoughts?

      I understand it would require editing the feed-rss2.php file in some way right?

      1. To get the image above the content all you’ll need to do is remove the CSS from this snippet, so just remove this code: “, array( ‘style’ => ‘float:right; margin:0 0 10px 10px;’ )”. If you’re using the image as a header image then you may also want to change the size from ‘medium’ to ‘large’ (or any other custom size defined by your theme/plugins). That won’t get it above the title and date though – you’re right in thinking that you will have to modify the RSS template for that.

    2. If you’re using Feedburner then the issue most likely that Feedburner is caching your feed and it will only refresh the new content at some point in the future. Other than that there’s no reason why this snippet wouldn’t work.

  6. Thanks for sharing this! I have an odd related question: would it be possible to add code that includes the URL to the featured image, but doesn’t display it on the visible feed item?

    I am looking to pull the Featured Image URL from each of my posts via the RSS feed, and display that image — hyperlinked to the related post — on a separate website. Basically I want to display thumbnails for current posts from the blog on the sidebar of my art portfolio (the art portfolio site is not a WP site, it’s a hand-coded site).

    Since my posts already have the same image used for the Featured Image inserted into the body of the post, adding your code results in posts with the image included twice. Is there a way to include the Featured Image URL “behind the scenes”, so it is included in the RSS XML code, but not displayed to the viewer?

  7. This is a very handy snippet! ..But I’m using a purchased theme so I prefer to use it as a plugin to avoid having to keep track of which files I have to check after an update of the theme. I also used to hard code changes directly into my theme files but I find it very messy when I have to update to the latest versions..

  8. Hi, I had a quick question for you. I am trying to implement this solution to include the featured image in the post when there is only a snippet of the feed being used. When I view the full post in the feed my images render fine, but I would like the snippet feed to show a picture first, then the first few lines of text. Is this possible?

    1. Well this isn’t really a plugin – it’s just a code snippet that you should edit yourself to suit your needs. You should never just copy and paste other people’s code snippets without seeing if you can customise it for your use case. Besides, you’re wrong about not being able to style the image – you can use any CSS you like in the ‘style’ parameter inside the get_the_post_thumbnail() function to do this.

      1. Hi, and thanks for a great explanation about rss feeds and images. You say one should add the code in the theme’s functions.php file. I have never done this kind of code editing before but I have read that one should do changes in the child theme. Is this correct?

  9. I’ve input the code into my Child Theme Functions.php and I still can’t get the images to pull in my RSS feed. Any other suggestions?

    1. That would actually be a great improvement to this – I wrote this snippet some time ago and I think it definitely needs an upgrade. I’ll implement that sometime soon 🙂

  10. Hello all here, I have a wordpress blog and I tried to use this code but it is not working correctly, Can you guide me what version of wordpress is needed for this to work.

  11. dear,
    thank you for this function , but, am building an rss iOS app, how can i get the image link so i can add it to my app

  12. I just used your code as I am using our sites xml feed in our new business app I’m building and it works very nicely.

    It’s a very nice, clean bit of coding.

    Thanks for sharing ;D

  13. Hello!
    I extended your snippet a little bit to add a default image if the user has not set up one.

    function featured_image_in_feed( $content ) {
    $default_thumb = get_bloginfo(‘stylesheet_directory’).’/images/warks-news.png’;
    global $post;
    if( is_feed() ) {
    if ( has_post_thumbnail( $post->ID ) ){
    $output = get_the_post_thumbnail( $post->ID, ‘medium’, array( ‘style’ => ‘width:290px; height:auto; float:right; margin:0 0 10px 10px;’ ) );
    $content = $output . $content;
    } else {
    $output = ”;
    $content = $output . $content;

    return $content;

    add_filter( ‘the_content’, ‘featured_image_in_feed’ );

    Super useful. Thank you! 🙂

  14. Anyone have a snippet that would put the Featured Image as a SEPARATE component of the RSS feed, not integrated into the content block? For example URL of Featured Image

  15. Got this working very easily.

    I was originally going to use a plugin, but it was incompatible with the Feedburner plugin. Adding the snippet above to the functions.php file works beautifully. Thank you!

  16. Thanks for posting this. I tried pasting the code into my functions.php file in the theme root directory, however it just crashes my website and I have to re-upload the original file in order to get the website back up again. Any ideas?

    1. Dave, you must pasta only this:
      add_filter( ‘the_content’, ‘featured_image_in_feed’ );
      function featured_image_in_feed( $content ) {
      global $post;
      if( is_feed() ) {
      if ( has_post_thumbnail( $post->ID ) ){
      $output = get_the_post_thumbnail( $post->ID, ‘medium’, array( ‘style’ => ‘float:right; margin:0 0 10px 10px;’ ) );
      $content = $output . $content;
      return $content;


  17. Hello Hugh,

    I have 2 questions… I also have a MyBB forum and it pulls the feed. I’m using your code so an image will be included. How can I center the image above the excerpt?

    And, how can I add social links under the excerpts, Example Facebook etc… I see this done with some feeds and can’t figure how to get it done.


  18. Hi Hugh, trust your well!

    Anyway to modify your feed function to include the price of woocommerce products to the product feed?


  19. Your snippet is working great, an I am sure you will update it according to new versions of wordpress. We all need such creative persons like you who can give us some thing to cheer about. Also wordpress blog platform are the best on this planet.

  20. Hi Hugh,

    I’m a noob in wp or coding. I just came here when searching for featured image broken in IFTTT recipe. I’m very interested to apply this code in my functions… And it makes me noticed, that (maybe) something wrong with my feed at all. It just shown the Unicode in the browser when I typed /feed.

    Could you help me? Thank so much.
    This is the problem I faced and googled for a while.

Leave a Reply