shortcode - Detecting embeded video format

admin2025-06-02  1

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
}
Share Improve this question asked Feb 6, 2019 at 7:51 Ferdy SopianFerdy Sopian 132 bronze badges 8
  • what do you get in return, when you place echo '<pre>', print_r( $video_embeded ), '</pre>'; right after your first line? – honk31 Commented Feb 6, 2019 at 9:39
  • it will show the video player. I didn't get any code in there if I dump or echo in a pre tag, it will show the video player. – Ferdy Sopian Commented Feb 6, 2019 at 9:54
  • ok. so it returns the video code. bueno. please add the following to your functions.php and report back: function 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
  • it show an Array <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:31
  • OK. one step further.. please replace this one with the previous code: function 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
 |  Show 3 more comments

1 Answer 1

Reset to default 0

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);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748841673a314172.html

最新回复(0)