WordPress 首页上的 header youtube 视频没有声音

WordPress No sound in header youtube video on Frontpage

我尝试在我的主题中使用 the_custom_header_markup(); 在页面顶部创建一个视频循环,就像基本主题 twentySeventeen 中出现的那样,我不知道如何打开视频声音。

视频由文件控制/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'), array( 'jquery-masonry' ), false, 1 ); }

  3. 现在我们可以通过多种方式控制视频,打开文件中的声音 wp-custom-header.js 搜索并删除行 e.target.mute(); (wordpress 4.9 中的第 390 行)。 8 或 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();
                }, ...

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

尽情享受吧!