0

i try to use the_custom_header_markup(); in my theme for create a video loop in the top of the page like appears in the base theme tweetySeventeen and i can't figured how turn on the video sound.

4

1 回答 1

1

视频由文件控制/wp-includes/js/wp-custom-header.js

要在您的主题中自定义它们,您需要覆盖此文件。

  1. 将此文件复制到您的资产中,从您网站的根目录写入

    cp wp-includes/js/wp-custom-header.js wp-content/themes/[你的主题]/assets/js/wp-custom-header.js

  2. [Your Theme]/functions.php 在添加此代码时注册新文件

    add_action('wp_enqueue_scripts', 'register_header_script');

    函数 register_header_script() { wp_deregister_script('wp-custom-header'); wp_register_script('wp-custom-header', get_theme_file_uri('/assets/js/wp-custom-header.js'), 数组('jquery-masonry'), false, 1); }

  3. 现在我们可以通过多种方式控制视频,在文件搜索中打开声音wp-custom-header.js并删除行 e.target.mute();(wordpress 4.9.8 中的第 390 行或 WordPress 5.5.1 中的第 394 行)

            handler.player = new YT.Player( video, {
            height: this.settings.height,
            width: this.settings.width,
            videoId: this.settings.videoUrl.match( VIDEO_ID_REGEX )[1],
            events: {
                onReady: function( e ) {
                    e.target.mute();
                    handler.showControls();
                }, ...

        handler.player = new YT.Player( video, {
            height: this.settings.height,
            width: this.settings.width,
            videoId: this.settings.videoUrl.match( VIDEO_ID_REGEX )[1],
            events: {
                onReady: function() {
                    // e.target.mute();
                    handler.showControls();
                }, ...

除了您可以在此文件中自定义之外,还存在许多其他标题的视频功能。

享受 !

于 2018-11-27T19:36:30.940 回答