YouTube thumbnail from video url

<?php
/**
* Get YouTube thumbnail from video url
*
*/
function be_youtube_thumbnail( $video_url ) {
$y_id = preg_replace( '~(?:http|https|)(?::\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[a-z0-9;:@#?&%=+\/\$_.-]*~i', '$1', $video_url );
$image = $y_id ? '<img src="https://img.youtube.com/vi/' . $y_id . '/0.jpg" />' : false;
return $image;
}
view raw functions.php hosted with ❤ by GitHub

youtube