Created
April 11, 2012 15:40
-
-
Save ramseyp/2360107 to your computer and use it in GitHub Desktop.
Video shortcodes for Youtube, Vimeo, Ustream
This file contains hidden or 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 | |
| /* Shortcodes for Vimeo, Youtube, and Ustream | |
| * | |
| * @author Pat Ramsey | |
| * @link http://slash25.com/vimeo-and-youtube-iframe-shortcodes/ | |
| * @param string $src, | |
| * @param optional string $width, $height | |
| * @return string iframe with modified strings $show_src, $show_width, $show_height | |
| * | |
| */ | |
| // Vimeo | |
| add_shortcode('vimeo', 's25_vimeo_shortcode'); | |
| function s25_vimeo_shortcode($atts) { | |
| extract(shortcode_atts(array( 'src' => '','width' => '','height' => ''), $atts)); | |
| if ($src) $show_src = esc_url(str_replace('http://vimeo.com/','http://player.vimeo.com/video/',$src), array('http')); | |
| if ($width) $show_width = ' width="'.$width.'"'; | |
| if ($height) $show_height = ' height="'.$height.'"'; | |
| return '<iframe src="'.$show_src.'?title=0&byline=0&portrait=0" '.$show_width.$show_height.' frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'; | |
| } | |
| // Youtube | |
| add_shortcode('youtube', 's25_youtube_shortcode'); | |
| function s25_youtube_shortcode($atts) { | |
| extract(shortcode_atts(array( 'src' => '','width' => '','height' => ''), $atts)); | |
| if ($src) $show_src = esc_url(str_replace('watch?v=','embed/',$src), array('http')); | |
| if ($width) $show_width = ' width="'.$width.'"'; | |
| if ($height) $show_height = ' height="'.$height.'"'; | |
| return '<iframe '.$show_width.$show_height.' src="'.$show_src.'" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'; | |
| } | |
| // Ustream | |
| add_shortcode('ustream', 's25_ustream_shortcode'); | |
| function s25_ustream_shortcode($atts) { | |
| extract(shortcode_atts(array( 'src' => '','width' => '','height' => ''), $atts)); | |
| if ($src) $show_src = esc_url(preg_replace('/recorded/','/embed/$0',$src), array('http')); | |
| if ($width) $show_width = ' width="'.$width.'"'; | |
| if ($height) $show_height = ' height="'.$height.'"'; | |
| return '<iframe src="'.$show_src.'" '.$show_width.$show_height.' scrolling="no" frameborder="0" style="border: 0px none transparent;"></iframe>'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment