Skip to content

Instantly share code, notes, and snippets.

@onnayokheng
Last active August 29, 2015 14:06
Show Gist options
  • Save onnayokheng/fa5f7b6e8f6ae3461dc6 to your computer and use it in GitHub Desktop.
Save onnayokheng/fa5f7b6e8f6ae3461dc6 to your computer and use it in GitHub Desktop.
get youtube thumbnail from content
<?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