admin管理员组文章数量:1428193
I have a lecture on YouTube that I would like to use as the header movie for my twentyseventeen child themed website. I would like it with sound and without autoplay (As viewed on YouTube, the video has sound intact).
Following another question about autoplay, I set a video URL of ;autoplay=0. The behavior does not appear to have changed. It starts immediately, but sound is muted.
How, with twentyseventeen, do I have an option of a media file that starts paused, and begins to play, with sound, if the user hits the 'Play' button?
I have a lecture on YouTube that I would like to use as the header movie for my twentyseventeen child themed website. I would like it with sound and without autoplay (As viewed on YouTube, the video has sound intact).
Following another question about autoplay, I set a video URL of https://www.youtube./watch?v=1dYAYBNU6qM&autoplay=0. The behavior does not appear to have changed. It starts immediately, but sound is muted.
How, with twentyseventeen, do I have an option of a media file that starts paused, and begins to play, with sound, if the user hits the 'Play' button?
Share Improve this question edited Jun 14, 2022 at 15:27 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Jan 21, 2018 at 1:10 Christos HaywardChristos Hayward 5,99317 gold badges61 silver badges116 bronze badges 3- it's default WordPress bug they set video autoplay by default if you want to stop that then you have to change core JS file /wp-includes/js/wp-custom-header.min.js fine autoplay:1 replace it with autoplay:0 then it stop autoplay – Mukesh Panchal Commented Jan 25, 2018 at 5:23
- how are you embedding the video - can you show the html/php? – Stender Commented Jan 26, 2018 at 10:10
- because it seems like your iframe has : allow="autoplay" - and your URL has autoplay=1 – Stender Commented Jan 26, 2018 at 10:11
1 Answer
Reset to default 5 +50You can use global
object wp
for get access to youtube player functions. Youtube video in twentyseventeen theme
loads wp-custom-header.js file and creating new object in 384 line.
Here is some solution you can use:
var ww_timer = setTimeout(function ww_video() {
if(wp.customHeader.handlers.youtube.player == null){
ww_timer = setTimeout(ww_video, 50);
}else {
if(typeof wp.customHeader.handlers.youtube.player.unMute === "function") {
wp.customHeader.handlers.youtube.player.unMute();
wp.customHeader.handlers.youtube.player.stopVideo();
}else{
ww_timer = setTimeout(ww_video, 50);
}
}
}, 50);
This code goes to my_js.js
file( I created it in the main directory of active child theme. You can add this code to another .js
, if you have it ) of your active child theme. Also, we need to update functions.php
file using this code:
function ww_youtube_functions(){
wp_enqueue_script('ww_youtube_video',get_stylesheet_directory_uri().'/my_js.js',array('wp-custom-header'),false, true);
}
add_action('wp_enqueue_scripts', 'ww_youtube_functions');
Required part of this code is array('wp-custom-header')
: enqueue script with dependence with script wp-custom-header
.
setTimeout
is not best way. I believe, that it can be done with more elegant code.
But its tested and working.
本文标签: javascriptHow can I unmute (and turn off autoplay) a YouTube video for twentyseventeenStack Overflow
版权声明:本文标题:javascript - How can I unmute (and turn off autoplay) a YouTube video for twentyseventeen? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745515934a2661537.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论