DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Introduced in WordPress 2.9, get_the_post_thumbnail() allow you to display a thumbnail in your posts. But what about displaying post thumbnails in RSS feeds? Just read this recipe to know how to do.

Simply paste the following code in your functions.php file. The post thumbnail should be visible once you saved the file.

function diw_post_thumbnail_feeds($content) {
	global $post;
	if(has_post_thumbnail($post->ID)) {
		$content = '<div>' . get_the_post_thumbnail($post->ID) . '</div>' . $content;
	}
	return $content;
}
add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
add_filter('the_content_feed', 'diw_post_thumbnail_feeds');

Thanks to Jeff Starr for this great tip!

Tags

5 Comments

  1. Hi i tried this hack but it gives error Fatal error: Call to undefined function add_filter() in wp-includes/functions.php on line 33 . please help me to solve this porblem. thanx in advance.

  2. Seems cool… but all this does is slaps an image tag into the beginning of the body or excerpt in the RSS feed.

    Is there a way to actually create a separated RSS item for the thumbnail? Not sure that’s the right terminology, but fancier parsing mechanisms (like mailchimp) let you do things with the image separate from the body which is really cool … but if it’s part of the body then you can’t really do anything clever.

  3. Apu Kumar Ghose

    Hi!

    I just used the above code at the bottom function.php (available inside the wp theme folder). But didn’t show up the thumbnail.

    I used RSS Aggregator to feed news. I want to show thumbnail related to each news. So, I used the above code. Unfortunatelt, it didn’t work

  4. If it doesn’t work for you, go to your feedburner page > troubleshootize > scroll down to resync now. Click it and check your feed.

    I tried a few codes before this one, and this is the only one that worked.

    Thanks!

  5. Hello everybody if you have used this code and your final results comes with an ugly character before the text this results for the encoding of the code, to avoid that the text look like this:

    [image]
    Aello, welcome to…

    I use the following code plus adding my custom post type to the RSS feed:

    // Add a Custom Post Type to a feed
    function myfeed_request($qv) {
    if (isset($qv[‘feed’]) && !isset($qv[‘post_type’]))
    $qv[‘post_type’] = array(‘post’, ‘my_custom_post_type’);
    return $qv;
    }
    add_filter(‘request’, ‘myfeed_request’);

    //Post Thumb in RSS
    function thumbnail_in_rssfeed($content) {
    global $post;
    if (isset($content[‘post_type’]))
    $content[‘post_type’] = array(‘post’, ‘my_custom_post_type’);
    if(has_post_thumbnail($post->ID)) {
    $content = ” . get_the_post_thumbnail($post->ID) . ” . get_the_excerpt();
    } else { $content = get_the_excerpt(); }
    return $content;
    }
    add_filter(‘the_excerpt_rss’, ‘thumbnail_in_rssfeed’);
    add_filter(‘the_content_feed’, ‘thumbnail_in_rssfeed’);

    And finally I have a beautiful RSS feed with my thumbnail well positioned and my text as it has to be shown. Greeting to all and Happy Coding

Leave a Comment

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