I need to get the video format from the shortcode. Example if i set my post meta "_video_format_embed" with [video src="/myvideo.mp4" /]
.
how to get the video format of my shortcode?
$video_embeded = get_post_meta(get_the_ID(), '_video_format_embed');
$video_format = '???'; // please help
if('mp4' === $video_format){
//some code
}
I need to get the video format from the shortcode. Example if i set my post meta "_video_format_embed" with [video src="https://url.domain/myvideo.mp4" /]
.
how to get the video format of my shortcode?
$video_embeded = get_post_meta(get_the_ID(), '_video_format_embed');
$video_format = '???'; // please help
if('mp4' === $video_format){
//some code
}
so you place your video inside a shortcode and then you can run a filter on that shortcode function. works like this (to be placed inside functions.php or some custom plugin):
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 '<pre>' . print_r($video_meta, true) . '</pre>';
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);
echo '<pre>', print_r( $video_embeded ), '</pre>';
right after your first line? – honk31 Commented Feb 6, 2019 at 9:39function so327822_wp_video_shortcode($output, $atts, $video, $post_id, $library) { echo '<pre>', print_r($atts), '</pre>'; echo '<pre>', print_r($video), '</pre>'; echo '<pre>', print_r($library), '</pre>'; } add_filter('wp_video_shortcode', 'so327822_wp_video_shortcode', 10, 5);
its a filter, that hooks into the wordpress video shortcode function.. – honk31 Commented Feb 6, 2019 at 10:50<pre>Array ( [src] => http://domain/video.mp4 [poster] => [loop] => [autoplay] => [preload] => metadata [width] => 640 [height] => 360 [class] => wp-video-shortcode [mp4] => [m4v] => [webm] => [ogv] => [flv] => ) 1</pre> <pre>1</pre> <pre>mediaelement1</pre>
– Ferdy Sopian Commented Feb 7, 2019 at 8:31function so327822_wp_video_shortcode($output, $atts) { $video_id = attachment_url_to_postid( $atts['src'] ); $video_meta = wp_get_attachment_metadata( $video_id ); echo '<pre>' . print_r($video_meta, true) . '</pre>';} add_filter('wp_video_shortcode', 'so327822_wp_video_shortcode', 10, 2);
and return back, i'm almost certain, that it includes the mime_type.. – honk31 Commented Feb 7, 2019 at 15:32