Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter foomarks

    (@foomarks)

    Solved, apply a filter to the_content:

    function catch_that_image() {
    global $post, $posts;
    $first_img = '';
    ob_start();
    ob_end_clean();
    $transformed_content = apply_filters('the_content',$post->post_content);
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $transformed_content, $matches);
    $first_img = $matches [1] [0];
    if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
    }
    return $first_img;
    }

Viewing 1 replies (of 1 total)