X

Shortcode for HTML5 video in posts

Adding the first snippet to the functions.php of your wordpress theme will create a new HTML5 video shortcode. Place the shortcode below in your posts to display your video.



Code Snippet:


function html5_video($atts, $content = null) {
extract(shortcode_atts(array(
"src" => '',
"width" => '',
"height" => ''
), $atts));
return '<video src="'.$src.'" width="'.$width.'" height="'.$height.'" controls autobuffer>';
}
add_shortcode('video5', 'html5_video');


Code Snippet:


[video5 src="http://your-site/videos/your-video.mp4" width="720" height="480"]

Comments  Leave a Reply

  1. How can there be multiple video files – same exact video but different sizes/resolutions for different screen sizes?

    1.  with this sample you really can’t do something like that, if you want to do something more advanced with wordpress and video I would look into http://jplayer.org/

  2. Below, not Bellow. Delete this comment once fixed. Thanks for another great snippet.

    1. Cheers Cliff, fixed the typo. Glad you like the snippet.

  3. this is a very nice snippet sir.

    1. Thanks glad that you like it.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!