-
-
Save billerickson/82fb6f24599f95501d36b79a360ac8b1 to your computer and use it in GitHub Desktop.
This file contains 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 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment