Skip to content

Instantly share code, notes, and snippets.

@rinatkhaziev
Created June 5, 2012 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rinatkhaziev/2877582 to your computer and use it in GitHub Desktop.
Save rinatkhaziev/2877582 to your computer and use it in GitHub Desktop.
HTML5 video shortcode for WordPress
<?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