$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>hooks - Transform .wp-video to the native video player of the browser|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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);
}
Post a comment

comment list (0)

  1. No comments so far