Add featured image to RSS feed through child theme functions.php file

I’m trying to add featured images to my RSS feed, on a blog running a pinbin child theme.

When I install and activate the plugin “Add featured image to RSS feed” it works.

Read More

When I try to paste the code of this plugin in my child functions.php file it doesn’t work (in fact, no code I’ve found on the internet works when it’s pasted in my functions.php file, like this one for example Can’t Display Featured Image in RSS Feed )

The code is

function add_featured_image_to_feed($content) {
    global $post;
    if ( has_post_thumbnail( $post->ID ) ){
        $content = '' . get_the_post_thumbnail( $post->ID, 'large' ) . '' . $content;
    }
    return $content;
}

add_filter('the_excerpt_rss', 'add_featured_image_to_feed', 1000, 1);
add_filter('the_content_feed', 'add_featured_image_to_feed', 1000, 1);

What could I be doing wrong? Of course my blog is using the child theme and I’ve checked that other functions in the child functions.php file are working.

Related posts

1 comment

  1. You may need to clear your Feeds cache to see the image after adding this code.

    function wpsitesdotnet_post_thumbnail_rss($content) {
    
    global $post;
    
    if ( has_post_thumbnail( $post->ID ) ){
    
    $content = '' . get_the_post_thumbnail( $post->ID, 'rss-image', array( 'class' =>   
    
    'aligncenter' ) );  
    
    }
    
    return $content;
    
    }
    
    add_filter('the_content_feed', 'wpsitesdotnet_post_thumbnail_rss');
    add_filter('the_excerpt_rss', 'wpsitesdotnet_post_thumbnail_rss');
    

    Source http://wpsites.net/web-design/add-featured-image-thumbnail-from-post-to-rss-feed/

Comments are closed.