Created
June 5, 2012 20:26
-
-
Save rinatkhaziev/2877582 to your computer and use it in GitHub Desktop.
HTML5 video shortcode for WordPress
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 | |
/** | |
* Shortcode callback [video5 src="" width="" height=""] | |
* | |
* @param array atts shortcode atts | |
* @return string HTML5 video tag | |
*/ | |
add_shortcode( 'video5', function( $atts, $content = null ) { | |
global $content_width; | |
extract( shortcode_atts( array( | |
"src" => '', | |
"width" => '', | |
"height" => '', | |
), $atts ) ); | |
// Sanitize a bit | |
$width = (int) $width !== 0 ? $width : $content_width; | |
$height = (int) $height !== 0 ? $height : (int) ( $width / 16 ) * 9; | |
// Validate the link and return the output | |
if ( filter_var( $src, FILTER_VALIDATE_URL ) ) | |
return '<video src="'.$src.'" width="'.$width.'" height="'.$height.'" controls autobuffer>'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment