这是完全未经测试的,但我很确定我刚才为您编写的这个短代码插件会起作用。你可能需要调整一下。请让我知道任何一种方式。
短码:[videotag option1="value1" option2="value2"]
例子:[videotag src="http://path.com/to/video.mp4" height="400" width="300" controls="controls"]
<?php
/*
Plugin Name: Add \'videotag\' shortcode
Plugin URI: http://wordpress.stackexchange.com/questions/12059/how-to-allow-video-html5-tag-in-wordpress
Description: Adds support for <video> HTML tag described here: http://diveintohtml5.org/video.html
Supports the attributes described here: http://www.w3schools.com/html5/tag_video.asp (warning: http://w3fools.com/)
Author: http://wordpress.stackexchange.com/users/1860/
*/
function build_video_tag_html_embed($atts, $content = null) {
extract( shortcode_atts( array(\'audio\'=>\'\',
\'autoplay\'=>\'\',
\'controls\'=>\'\',
\'height\'=>\'\',
\'loop\'=>\'\',
\'poster\'=>\'\',
\'preload\'=>\'\',
\'src\'=>\'\',
\'text\'=>\'This browser doesn\\\'t support the <pre><video></pre> tag.\',
\'width\'=>\'\'), $atts));
/* Sanitize some stuff */
$text = sanitize_text_field($text);
$width = intval($width);
$height = intval($height);
$html_to_return .= "<video";
if( !empty($audio) ) {
$html_to_return .= " audio=\'" . esc_attr($audio) . "\'";
}
if( !empty($autoplay) ) {
$html_to_return .= " autoplay=\'" . esc_attr($autoplay) . "\'";
}
if( !empty($controls) ) {
$html_to_return .= " controls=\'" . esc_attr($controls) . "\'";
}
if( !empty($height) ) {
$html_to_return .= " height=\'" . esc_attr($height) . "\'";
}
if( !empty($loop) ) {
$html_to_return .= " loop=\'" . esc_attr($loop) . "\'";
}
if( !empty($poster) ) {
$html_to_return .= " poster=\'" . esc_attr($poster) . "\'";
}
if( !empty($preload) ) {
$html_to_return .= " preload=\'" . esc_attr($preload) . "\'";
}
if( !empty($src) ) {
$html_to_return .= " src=\'" . esc_attr($src) . "\'";
}
if( !empty($width) ) {
$html_to_return .= " width=\'" . esc_attr($width) . "\'";
}
$html_to_return .= ">{$text}</video>";
}
add_shortcode(\'videotag\', \'build_video_tag_html_embed\');
?>
有趣的问题。这将是一个很好的补丁,也许是我将提交的第一个补丁。