프리이미지
사이트 내 전체검색

YouTube shortcode fix for a blog imported from WordPress.com

페이지 정보

작성일13-07-15 08:30

본문

  1. [youtube=http://www.youtube.com/watch?v=1LLls4hPEfM&w=500&h=311]  

This is actually pretty easy to fix once your figure out the regular expression that can grab the YouTube video id, width and height from the shortcode. Then you add a shortcode definition to the functions.php file of your theme by copying and pasting this code:

  1. function youtubeSC($atts) {  
  2.     $posttext = substr($atts[0],1);  
  3.     preg_match('/v\=([a-zA-Z0-9]+)/'$posttext$youtubeID);  
  4.     preg_match('/w\=([0-9]+)/'$posttext$width);  
  5.     preg_match('/h\=([0-9]+)/'$posttext$height);  
  6.       
  7.     return '<iframe width="' . $width[1] . '" height="' . $height[1] . '" src="http://www.youtube.com/embed/' . $youtubeID[1] . '" frameborder="0" allowfullscreen></iframe>';  
  8. }  

Hope that helps!

게시물 검색