Are you looking for a way to create a shortcode for HTML5 video? This snippet will create a new shortcode for adding HTML5 video to your posts and pages.
- Add this code to your theme’s functions.php file or in a site-specific plugin.
- Then, add this shortcode to your post or page and configure it as needed. Remember to replace the
src
attribute value.
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');
[video5 src="http://your-site/videos/your-video.mp4" width="720" height="480"]
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 12 Best WordPress Podcast Plugins Compared (Free & Premium).
How can there be multiple video files – same exact video but different sizes/resolutions for different screen sizes?
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/
Below, not Bellow. Delete this comment once fixed. Thanks for another great snippet.
Cheers Cliff, fixed the typo. Glad you like the snippet.
this is a very nice snippet sir.
Thanks glad that you like it.