If you often add YouTube video to your website, then definitely you wish to display a thumbnail from a YouTube video. This can be done simply by using the snippet below in your theme’s functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /* Shortcode to display youtube thumbnail on your wordpress blog. Usage: [youtube_thumb id="VIDEO_ID" img="0" align="left"] VIDEO_ID= Youtube video id img=0,1,2 or 3 align= left,right,center */ function wp_youtube_video_thumbnail($atts) { extract(shortcode_atts(array( 'id' => '', 'img' => '0', 'align'=>'left' ), $atts)); $align_class='align'.$align; return '<img src="<a href="http://img.youtube.com/vi/'.$id.'/'.$img.'.jpg"" rel="nofollow">http://img.youtube.com/vi/'.$id.'/'.$img.'.jpg"</a>; alt="" class="'.$align_class.'" />'; } add_shortcode('youtube_thumb', 'wp_youtube_video_thumbnail'); |
Once done, all you have to do is to use the shortcode below:
1 | [youtube_thumb id="rNWeBVBqo2c" img="0" align="center"] |
Snippet Source/Credit: Gunay