• I want to use the function catch_that_image() but modify it so it will catch that first image or youtube video and return it all in the same function. Also want to append ?enablejsapi=1 to the end of the youtube url.

    So <?php echo catch_that_image() ?> will get the first image or youtube video

    Trying to integrate it will my flex slider

    Current image only function

    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches[1][0];
    
      if(empty($first_img)) {
        $first_img = "/path/to/default.png";
      }
      return $first_img;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter badincite

    (@badincite)

    Found this function to grab the video but doesn’t seem to be working how can I combine the two and get them working?

    function catch_video() {
      global $post, $posts;
      $first_vid = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_vid = $matches [1] [0];
    
      if ($output == '1') {
      echo '<iframe width="450" height="310" src="';
      echo $first_vid;
      echo '" frameborder="0" allowfullscreen></iframe>';
      }
    }
    Thread Starter badincite

    (@badincite)

    Anyone?

    Thread Starter badincite

    (@badincite)

    ?’

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Catch first image or video and return’ is closed to new replies.