Home / functions.php / Add featured image to RSS feed
  • How to Add featured image to RSS feed

    add-featured-image-rss-feed

    It’s often useful to spruce up your RSS feed with images and the simplest way to do this is to include your post’s featured image in the feed content. Some themes have an option to enable this, but if yours does not then you can use this snippet. 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.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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;
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, get_the_post_thumbnail, the_post, has_post_thumbnail, add_filter, is_feed,
  • Great snippet, Hugh! :)

    How about hooking this on to “the_content_feed” and “the_excerpt_rss”?