Created
May 20, 2010 00:03
-
-
Save artlung/407022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this to functions.php in your theme to allow youtube | |
// video shortcodes like wordpress.com does: | |
// http://en.support.wordpress.com/videos/youtube/ | |
function youtube_shortcode_func($atts) { | |
extract(shortcode_atts(array( | |
'youtube' => '', | |
), $atts)); | |
$url = $atts[0]; | |
$url_p = parse_url($url); | |
$url_q = $url_p['query']; | |
$q_parts = explode('&', $url_q); | |
$youtube = array(); | |
$legal_parts = array('v', 'w', 'h', 'hd', 'showsearch', 'rel', 'fs'); | |
foreach($q_parts as $str) { | |
list($key, $value) = explode('=', $str); | |
if (in_array($key, $legal_parts)) { | |
$youtube[$key] = $value; | |
} | |
} | |
(!isset($youtube['rel'])) { | |
$youtube['rel'] = 0; | |
} | |
(!isset($youtube['fs'])) { | |
$youtube['fs'] = 1; | |
} | |
return "<object width=\"{$youtube['w']}\" height=\"{$youtube['h']}\"><param name=\"movie\" value=\"http://www.youtube.com/v/{$youtube['v']}&fs={$youtube['fs']}&rel={$youtube['rel']}\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/{$youtube['v']}&fs={$youtube['fs']}&rel={$youtube['rel']}\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"{$youtube['w']}\" height=\"{$youtube['h']}\"></embed></object>"; | |
} | |
add_shortcode('youtube', 'youtube_shortcode_func'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment