How to show post thumbnail to RSS feed in WordPress

If you wish to show post thumbnail image in your RSS feed instead of text content. Then here is the useful snippet function. It will add the post feature thumbnail before your content.
Add the following function to the function.php file in your child theme.

// Adding Post Thumbnail into RSS feed

function wps_rss_post_thumbnail( $data ) {

   global $post;

   if( has_post_thumbnail( $post->ID ) ) {

      $data = '<p>'. get_the_post_thumbnail($post->ID). '</p>'. get_the_content();

   }

    return $data;

}

add_filter('the_excerpt_rss', 'wps_rss_post_thumbnail');

add_filter('the_content_feed', 'wps_rss_post_thumbnail');

Here in the above function, we are checking the post feature image using the global variable
$post->ID.

However, if the post has a featured image we are getting it in the $data variable, then we are returning the $data variable with the final outcome.

With the help of add_filter, we are displaying the excerpt, content, and also passing the function which is wps_rss_post_thumbnail.

You can check the final outcome on Your-domain/feed in between the <item> tag.

Leave a Comment

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

Scroll to Top