Skip to content

Instantly share code, notes, and snippets.

@lepittenger
Last active July 28, 2017 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lepittenger/f6352e4abce5ae4ef2d059a7d8bf5cd1 to your computer and use it in GitHub Desktop.
Save lepittenger/f6352e4abce5ae4ef2d059a7d8bf5cd1 to your computer and use it in GitHub Desktop.
Display a YouTube Thumbnail
<?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