I'm successfully using fetch_feed() to display an RSS feed inside a dashboard widget. However, I'm unable to load the thumbnail image from the items in the feed. I'm attempting to do it with the get_image_url() method, however, WordPress errors out on that method as an undefined method.

Code is below...

function example_dashboard_widget_function() {
    // Display whatever it is you want to show   
    $rss = fetch_feed( "http://localhost/testsite/wp-content/test.rss" );

     if ( is_wp_error($rss) ) {
          if ( is_admin() || current_user_can('manage_options') ) {
               echo '<p>';
               printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
               echo '</p>';

if ( !$rss->get_item_quantity() ) {
     echo '<p>No RSS items to show!</p>';

echo "<ul>\n";

if ( !isset($items) )
     $items = 10;

     foreach ( $rss->get_items(0, $items) as $item ) {
          $publisher = '';
          $site_link = '';
          $link = '';
          $content = '';
          $date = '';
          $image = '';

          $image = $item->get_image_url();
//        $image = esc_url( strip_tags( $item->get_thumbnail() ) );

          $link = esc_url( strip_tags( $item->get_link() ) );

          $content = $item->get_content();
          $content = wp_html_excerpt($content, 250) . ' ...';

         echo "<li><img src='$image' /><a href='$link'>$link</a> - $content</li>\n";

echo "</ul>\n";


It's a method for completely different thing.

RSS 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to have a “feed logo”, which is a single image to represent the feed. This method returns the notated URL for that image/logo file. get_image_url()

And it complains about undefined because it is method of feed object and you are iterating through feed item objects.

Overall it depends on how your feed works with images. If they are simply included in content - mine them from there (with regex or something simpler if not much text). If images are included in media enclosure try get_enclosures() method.

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.