사이트 내 전체검색
YouTube shortcode fix for a blog imported from WordPress.com
로빈아빠
https://cmd.kr/javascript/863 URL이 복사되었습니다.

본문

  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!

댓글목록

등록된 댓글이 없습니다.

833 (1/17P)

Search

Copyright © Cmd 명령어 18.97.14.87