Are you looking for a way to add the featured image to your RSS feed? This snippet will display the featured image of the post in the RSS feed. It will display the image to the right of the first paragraph of your content, but you can change the CSS in the snippet to modify the layout.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
add_filter( 'the_content', 'featured_image_in_feed' ); function featured_image_in_feed( $content ) { global $post; if( is_feed() ) { if ( has_post_thumbnail( $post->ID ) ){ $output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) ); $content = $output . $content; } } return $content; }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out 12 Best WordPress Plugins for Affiliate Marketers.
Great snippet, Hugh! 🙂
How about hooking this on to “the_content_feed” and “the_excerpt_rss”?