WordPress does not allow featured post thumbnails in feeds even if you enable the post thumbnails support. But we have a solution for that. Here is how you can add post thumbnails to your WordPress RSS feeds with a simple function.
Just copy and paste this code snippet in your theme functions.php file and your RSS feeds will display featured post thumbnails along with content.
// display featured post thumbnails in WordPress feeds
function wcs_post_thumbnails_in_feeds( $content ) {
global $post;
if( has_post_thumbnail( $post->ID ) ) {
$content = '<p>' . get_the_post_thumbnail( $post->ID ) . '</p>' . get_the_content();
}
return $content;
}
add_filter( 'the_excerpt_rss', 'wcs_post_thumbnails_in_feeds' );
add_filter( 'the_content_feed', 'wcs_post_thumbnails_in_feeds' );
I have applied you told. It is working well. But I want to get imgURL and imgTitle as seperate XML key elements. How can I do that?
You will have to create and customize feed template for that.
Let me know if you need help with that. ;)
Thanks for this help. I was shocked when i first saw my feed in feedly. After i applied this changes i get the correct result.
Thanks Dirk for your feedback,
I’m glad you found it useful :)
I added this code snippet but it wont work with MailChimp online editor. It adds inside tag. I even changed to:
$content = ‘ID), ‘thumbnail’) . ‘” medium=”image” type=”image/png”/> ‘ . get_the_content();
but it still wont work. Is there other way to add to RSS Feed and that it works with *|FEEDITEM:IMAGE|* or *|RSSITEM:IMAGE|* ?