我正在尝试为我的amp页面格式化wordpress博客的视频。我在content editor中使用的代码是:
[video width="768" height="576" mp4="https://mywebsite.com/wp-content/uploads/20**/0*/video-name.mp4"][/video]
我想以以下格式在AMP页面中显示此视频:<amp-video controls
width="640"
height="360"
layout="responsive">
<source src="https://mywebsite.com/wp-content/uploads/20**/0*/video-name.mp4" />
</amp-video>
我尝试了以下功能,但它们对我不起作用。Try 1:
function am_video_amp_format($content){
global $post;
$pattern ="~<video(.*?)></video>~i";
$replacement = \'<amp-video controls
width="640"
height="360"
layout="responsive">
<source src="$2" />
</amp-video>\';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter(\'the_content\', \'am_video_amp_format\');
Try 2:
function am_video_amp_format($content){
global $post;
$pattern ="~<iframe(.*?)>(.*?)<video(.*?)src=\\"(.*?)\\">(.*?)</video>(.*?)</iframe>~i";
$replacement = \'<amp-video controls
width="640"
height="360"
layout="responsive">
<source src="$4" />
</amp-video>\';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter(\'the_content\', \'am_video_amp_format\');
Try 3:
function am_video_amp_format($content){
global $post;
$pattern ="~<video(.*?)><source(.*?)src=\\"(.*?)\\"(.*?)></video>~i";
$replacement = \'<amp-video controls
width="640"
height="360"
layout="responsive">
<source src="$2" />
</amp-video>\';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter(\'the_content\', \'am_video_amp_format\');
我还能得到高度和宽度吗?非常感谢。