Family Encyclopedia >> Electronics

How to Add Featured Images to Your WordPress RSS Feeds

Building on our popular guide to enabling post thumbnails in WordPress, we've found that these images often don't appear in RSS feeds by default. As experienced WordPress developers, we've tested a reliable solution that adds them seamlessly.

To implement this, open your theme's functions.php file and paste the following code snippet. This function checks for a featured image and prepends it to the feed content.

function rss_post_thumbnail( $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', 'rss_post_thumbnail' );
add_filter( 'the_content_feed', 'rss_post_thumbnail' );

Customize the styling to match your brand. First, ensure post thumbnails are enabled via our comprehensive tutorial. This approach has powered feeds for thousands of sites.

Source: Dave Redfern, WordPress Expert