Last active
July 28, 2017 21:49
-
-
Save lepittenger/f6352e4abce5ae4ef2d059a7d8bf5cd1 to your computer and use it in GitHub Desktop.
Display a YouTube Thumbnail
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 | |
/** | |
* | |
* Display a YouTube video thumbnail based on a URL in a template | |
* | |
*/ | |
$video_link = 'https://www.youtube.com/watch?v=B9duuy7lr08'; | |
if( !empty($video_link) ) { | |
parse_str( parse_url( $video_link, PHP_URL_QUERY ), $my_array_of_vars ); | |
$video_id = $my_array_of_vars['v']; | |
echo '<img src="https://i1.ytimg.com/vi/'. $video_id .'/hqdefault.jpg" />'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment