0

I am trying to fetch a full size Featured Image (or first image) of the post to appear within my RSS feed. See here

I am using the following code

function firstImg( $post ) {
    $matches = array();
    $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
    if ( isset( $matches[1][0] ) ) {
        $first_img = $matches[1][0];
    }

    if ( empty( $first_img ) ) {
        return '';
    }
    return $first_img;
}
add_filter('the_excerpt_rss', 'firstImg');

However, this is only fetching a 200x200 thumbnail size of the image. I want to use the full size which is 600px width.

What's missing in the code?

Thanks

  • 1
    It fetches the first found image URL in post content, may be you are using the 200x200 images there. – Abhik Feb 19 '14 at 15:36
  • 1
    If you are using the featured image feature of WordPress you should use the_post_thumbnail – kraftner Feb 19 '14 at 15:39
  • @abhik No, the ones in the content are 600px. I suppose, this is fetching the thumbnails which are set at 200x200 but I wanted otherwise. – tushonline Feb 19 '14 at 16:10
  • @kraftner Okay let me try that. – tushonline Feb 19 '14 at 16:12
  • Try declaring $post global variable. Also, you can first check if any featured image is available to fetch, if no featured images, pull the first found image. – Abhik Feb 19 '14 at 16:21

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.