WordPress display featured image in rss feed and feedburner

RSS feeds helps publishers to syndicate data online automaticatically in a standard XML file format. XML file format ensures compatibility with different machines or programs. RSS feeds also helps users to receive timely updates from favourate websites or to use data from many websites. In a recent wordpress projects I want to display featured image in rss feed and feedbuner feed. For that I found next code snippet which I used to add featured image to rss feeds.

Show Featured image in RSS feed and Feedbuner

function wp_featured_image_in_rss_feed( $content ) {
    global $post;
    if( is_feed() ) {
        if ( has_post_thumbnail( $post->ID ) ){
            $output = '<div style="display:block; clear:both;">'.get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) ).'</div>';
            $content = $output . $content;
        }
    }
    return $content;
}
add_filter('the_excerpt_rss', 'wp_featured_image_in_rss_feed');
add_filter('the_content_feed', 'wp_featured_image_in_rss_feed');

Add above code in your current wordpress themes functions.php file.

For demo you can check RSS feed of website at WordPress News

Leave a Reply

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