Catch first image or video and return
-
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)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Catch first image or video and return’ is closed to new replies.