Display youtube video with embed shortcode

Adding this snippet to your wordpress theme will let you embed youtube video with a simple shortcode to your posts. Just add the youtube url to the video and your ready to go although you can specify a few paramaters like width, height, name, etc.

 

 

function youtube($atts) {
extract(shortcode_atts(array(
"value" => 'http://',
"width" => '475',
"height" => '350',
"name"=> 'movie',
"allowFullScreen" => 'true',
"allowScriptAccess"=>'always',
), $atts));
return '<object style="height: '.$height.'px; width: '.$width.'px"><param name="'.$name.'" value="'.$value.'"><param name="allowFullScreen" value="'.$allowFullScreen.'"></param><param name="allowScriptAccess" value="'.$allowScriptAccess.'"></param><embed src="'.$value.'" type="application/x-shockwave-flash" allowfullscreen="'.$allowFullScreen.'" allowScriptAccess="'.$allowScriptAccess.'" width="'.$width.'" height="'.$height.'"></embed></object>';
}
add_shortcode("youtube", "youtube");

[youtube value="http://www.youtube.com/watch?v=1aBSPn2P9bg"]

Be Sociable, Share!

Leave a comment