3

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.

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.

  • I can't spot anything wrong with the code itself. It works fine on a quick test case. Error log giving you any clues? – Will the Web Mechanic Dec 27 '13 at 11:30
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/

  • Theme's style.css is not applied to feeds – shea Jan 3 '14 at 22:38
  • Yep, added it directly to the code now. – Brad Dalton Aug 16 '14 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.