我需要从短代码中获取视频格式。例如,如果我用_video_format_embed设置post元“[video src="https://url.domain/myvideo.mp4" /]
”。
如何获得我的短代码的视频格式?
$video_embeded = get_post_meta(get_the_ID(), '_video_format_embed');
$video_format = '???'; // please help
if('mp4' === $video_format){
//some code
}
发布于 2019-03-05 09:12:24
所以你把你的视频放在一个短代码中,然后你可以在这个短代码函数上运行一个过滤器。工作方式如下(放置在functions.php或某些自定义插件中):
function so327822_wp_video_shortcode($output, $atts) {
//get video ID by src
$video_id = attachment_url_to_postid( $atts['src'] );
//get video meta
$video_meta = wp_get_attachment_metadata( $video_id );
//uncomment next line, to view all meta
//echo '' . print_r($video_meta, true) . '';
if ( $video_meta['fileformat'] === 'mp4' ) {
//mess with $output here, if we have mp4
}
//return
return $output;
}
add_filter('wp_video_shortcode', 'so327822_wp_video_shortcode', 10, 2);
https://wordpress.stackexchange.com/questions/327822
复制相似问题