Posted By

florent on 10/21/11


Tagged

wordpress thumbnail YouTube shortcode


Versions (?)

how to display a thumbnail from a youtube using a shortcode


 / Published in: PHP
 

  1. /*
  2. Shortcode to display youtube thumbnail on your wordpress blog.
  3. Usage:
  4. [youtube_thumb id="VIDEO_ID" img="0" align="left"]
  5. VIDEO_ID= Youtube video id
  6. img=0,1,2 or 3
  7. align= left,right,center
  8. */
  9. function wp_youtube_video_thumbnail($atts) {
  10. extract(shortcode_atts(array(
  11. 'id' => '',
  12. 'img' => '0',
  13. 'align'=>'left'
  14. ), $atts));
  15. $align_class='align'.$align;
  16. return '<img src="<a href="http://img.youtube.com/vi/'.$id.'/'.$img.'.jpg&quot" rel="nofollow">http://img.youtube.com/vi/'.$id.'/'.$img.'.jpg&quot</a>; alt="" class="'.$align_class.'" />';
  17. }
  18. add_shortcode('youtube_thumb', 'wp_youtube_video_thumbnail');
  19.  
  20.  
  21.  
  22. Once done, you can use the shortcode. It accept 3 parameters: The video ID, the image size (0 for 480*360px, 1 for 120*90) and the image alignment.
  23.  
  24.  
  25.  
  26. [youtube_thumb id="rNWeBVBqo2c" img="0" align="center"]
  27.  
  28.  

Report this snippet  

You need to login to post a comment.