2

I am trying to pull the post thumbnail from an RSS feed to output on an external site. I am using the following function to add the post thumbnail to the site:

function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
    $content = '<p>' . get_the_post_thumbnail($post->ID, 'be_home') . '</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');

I am then using the fetch_feed function in WordPress (with this shortcode: http://www.kevinleary.net/display-rss-feeds-wordpress-shortcodes/) to generate the RSS feed. Whenever I try to get the image though, I get the following error:

Fatal error: Call to undefined method SimplePie_Item::get_thumbnail()

I have tried all of the following with the same result (though different function at the end of the error):

$image = $item->get_thumbnail();

$desc = $item->get_description();
$desc_dom = str_get_html($desc);
$image = $desc_dom->find('img', 0);
$image_url = $image->src;

$desc = $item->get_description();
$image = $desc->get_first_image_url();

$image = get_first_image_url($item->get_content());

Your Answer

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

Browse other questions tagged or ask your own question.