Grabbing YouTube ID from post
-
Hey guys,
I’ve been getting to know WordPress pretty well for about a year using it to post daily videos and news. I’ve built my own template and found this function here to grab the first image of a post
// Get URL of first image in a post 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]; // no image found display default image instead if(empty($first_img)){ $first_img = "DEFAULT-IMAGE"; } return $first_img; }
Well, I started using JR embed to give me flexibility with changing embed sizes in future layouts, and I decided I need to find a way to get the YouTube video ID from the post so I can have a loop with thumbnails of the videos… Is there a way to create a new function similar to the one for images so I can do this?
I have very little experience in PHP, and was hoping a nice soul might help me figure out how to create a function to do this, or to have a better way of managing the video posts within WordPress. I don’t want to use a custom field in the post because other people with less knowledge post updates.
Thanks in advance, I love the WordPress community!
- The topic ‘Grabbing YouTube ID from post’ is closed to new replies.