How to add WordPress featured image to RSS item

In my Ricard Torres Blog I use the featured image in my theme to show that image at the beginning of each post.

The problem is, that image is not included in the RSS feed because it's not part of the post content. So RSS subscribers or Mailchimp subscribers won't see that image.

It can be solved by adding this straightforward snippet as a plugin or just copying it to your theme's functions.php file.

Enjoy!

<?php

/*
Plugin Name: Add Featured Image to RSS Item
Plugin URI: http://php.quicoto.com
 * Description: It adds the post featured image at the beginning of the post in the RSS feed items.
 * Version: 1.0
 * Author: quicoto
 * Author URI: http://php.quicoto.com
*/

function add_featured_image_to_RSS ($content) {
  global $post;
  if ( has_post_thumbnail( $post->ID ) ){
    $content = get_the_post_thumbnail( $post->ID, 'full' ) . $content;
  }
  return $content;
}
   
add_filter('the_content_feed', 'add_featured_image_to_RSS');

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*