hooks - Transform .wp-video to the native video player of the browser

admin2025-06-06  1

Is there a way to display a video using only the default video player of the browser, without the mejs / wp-video interface? The additional markup gives me a lot of trouble. I just want to use the <video> element, and handle my custom needs with CSS/JS.

I won't say I'm an expert. I have considerable amount of experience with custom templates and hooks, but I can't figure this one out.

Is there a way to display a video using only the default video player of the browser, without the mejs / wp-video interface? The additional markup gives me a lot of trouble. I just want to use the <video> element, and handle my custom needs with CSS/JS.

I won't say I'm an expert. I have considerable amount of experience with custom templates and hooks, but I can't figure this one out.

Share Improve this question asked Oct 30, 2018 at 21:16 Nekomajin42Nekomajin42 1013 bronze badges 4
  • Maybe you could show us a bit of your code for us to be able to help you ? – Friss Commented Oct 30, 2018 at 22:39
  • I don't have any code yet, because I don't know how to start. I'd like to know if there is a hook for this, or a clue where to start looking. – Nekomajin42 Commented Oct 31, 2018 at 12:32
  • I gave you a possible answer with the embed_oembed_html filter – Friss Commented Oct 31, 2018 at 12:36
  • I am on phone, but give it a try soon. – Nekomajin42 Commented Oct 31, 2018 at 14:40
Add a comment  | 

2 Answers 2

Reset to default 0

I've found the right way digging through the WP documentation: https://developer.wordpress/reference/hooks/wp_video_shortcode/

This code seems to do the trick:

function buildVideoPlayer($output, $attr)
{
    // $output contains the default HTML string, created by the WP core
    // $attr is an associative array, which contains the parameters 
    // (src, poster, preload, etc.) specified in the shortcode

    // The following piece of HTML string will replace the default WP video player
    return "<video src='".$attr["mp4"]."'></video>";
}
add_filter("wp_video_shortcode", "buildVideoPlayer", 10, 2);

Make sure to pass how many parameters do you want to catch in add_filter(). The default value is 1, but wp_video_shortcode has 4, and in this code, I needed the 2nd one.

I would try to use the embed_oembed_html filter

Here is an ultra basic example

add_filter('embed_oembed_html','oembed_video_add_wrapper',10,4);

function oembed_video_add_wrapper( $cache, $url, $attr, $post_ID) {
        return sprintf('<video src="%s">',$url);
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749214387a317321.html

最新回复(0)