How to add Featured Images to your WordPress RSS Feed
(2018/01/30)

I discovered today that featured images are not added to WordPress RSS feeds by default. Following the Specifications here is a quick snippet that you can add to your functions.php file and get those images back in place.

As always, mileage may vary. Leave a comment if you have updates/issues/enhancements/etc.

Code
function add_thumbnail_to_rss() {
    global $post;
    if(has_post_thumbnail($post->ID)):
        $content = get_the_post_thumbnail_url($post->ID);
        $bytes = filesize(get_attached_file(get_post_thumbnail_id()));
        echo('<enclosure url="' . $content . '" length="' . $bytes . '" type="image/jpg" />');
    endif;
}

add_action('rss2_item', 'add_thumbnail_to_rss');

 

Leave a comment

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