Last active
August 29, 2015 14:06
-
-
Save onnayokheng/fa5f7b6e8f6ae3461dc6 to your computer and use it in GitHub Desktop.
get youtube thumbnail from content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Get thumbnail from Video Embed code */ | |
function nesia_get_video_image() { | |
global $post; | |
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $post->post_content, $match)) { | |
$video_id = $match[1]; | |
} else { | |
return false; | |
} | |
// YouTube - get the corresponding thumbnail images | |
if( isset($video_id) ) | |
$video_thumb = "http://img.youtube.com/vi/".$video_id."/0.jpg"; | |
// return whichever thumbnail image you would like to retrieve | |
return $video_thumb; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment