Adsense

Display a thumbnail from a Youtube using a shortcode

Copy the following code below and then paste it into the functions.php file under theme folder.

/*
    THis Shortcode will display youtube thumbnail on the 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;
   
}
add_shortcode('youtube_thumb', 'wp_youtube_video_thumbnail');

Now, you can use the shortcode. The shortcode accept 3 parameters: The video ID, the image size (0 for 480*360px, 1 for 120*90) and the image alignment.

[youtube_thumb id="8O9YA7PZZe0" img="0" align="center"]

Reference site: http://php-mysql-guide.blogspot.com

newest questions on wordpress