• Resolved Prasad Nevase

    (@prasad-nevase)


    Hey There,

    I am using WordPress’ latest custom video header feature. Anybody has an idea how to stop autoplay? Checked filters but did not find a way to disable autoplay.

    /wp-includes/js/wp-custom-header.js has the default settings. However not getting any clue how I may override it without editing core files ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    I cannot really answer your specific question, but you can override any JS function by simply re-declaring it. So if you write your own version, give it the same name, and ensure your version is loaded after the core version, yours will be the one used. This can be done when your script is enqueued with wp_enqueue_script(). This function should be called from an action callback to “wp_enqueue_scripts”. When you add your callback, specify a much later priority parameter.

    IIRC, depending on the video source, autoplay can be suppressed by a particular URL parameter added to the video URL. This of course would be preferred to overriding a JS function if it’s at all possible to do.

    You can just set autoplay attribute of the video tag to false.

    $( document ).ready( function() {
        $( document ).on( 'wp-custom-header-video-loaded', function() {
            $("#wp-custom-header-video").attr('autoplay',false);
        });
    });
    Thread Starter Prasad Nevase

    (@prasad-nevase)

    That works thanks. The thing is I was trying same snippet in Twenty Seventeen theme’s global.js file. Apparently… I did not notice that I was placing it outside of document.ready and hence it was not working. Thank you very much.

    Hello, I don’t understand where I can write this code ? Thanks

    • This reply was modified 7 years, 12 months ago by 1formanet.

    You need to add this in your theme’s javascript file.If you are using twentyseventeen you can place this in twentyseventeen/assets/js/gloabl.js though would recommend using child theme for any modifications.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Video Header – Stop Autoplay’ is closed to new replies.