๐ŸŽ Get Up To 70% Off and a Free Prize During Divi Black Friday Sale! Get Divi

How to Autoplay Videos in Divi Video Module And Hide Controls

Blog, Divi Tutorial | 148 comments

In this tutorial I will share the steps to autoplay videos in the Divi video module and hide the controls on the video.

Before we start with the tutorial it is important to know that it is not possible to autoplay videos with sound. Browsers will block the video from loading if you try to play it unmuted. You can learn more about the autoplay policy from Google at this link.

Another thing to note is that the autoplay code will only work on self hosted videos. This will not work for third party video players such as YouTube or Vimeo.

Now lets get started.

1. Add CSS Class To The Video Module

The first thing that you need to do is add a custom CSS Class to the Video module. This is so that the code does not affect all the video modules on your website.

You can add the CSS Class inside the Video Module Settings > Advanced > CSS ID & Classes > CSS Class. For this tutorial we will be adding the class lwp-video-autoplay to it.

Here is a screenshot to help you understand where to add the CSS Class in the video module settings.

Video Module Autoplay CSS Class

2. Add jQuery Code to Autoplay Video in Theme Options

Next you need to add the code below at your WordPress Dashboard > Theme Options > Integration > Add code to the < head > of your blog.

<script>
jQuery(document).ready(function() {
    if (jQuery('.lwp-video-autoplay .et_pb_video_box').length !== 0) {
        jQuery('.lwp-video-autoplay .et_pb_video_box').find('video').prop('muted', true);
        jQuery(".lwp-video-autoplay .et_pb_video_box").find('video').attr('loop', 'loop');
        jQuery(".lwp-video-autoplay .et_pb_video_box").find('video').attr('playsInline', '');

        jQuery(".lwp-video-autoplay .et_pb_video_box").each(function() {
            jQuery(this).find('video').get(0).play();
        });
        jQuery('.lwp-video-autoplay .et_pb_video_box').find('video').removeAttr('controls');
    }
});
</script>

That’s it. Now every video module on your website that has the class lwp-video-autoplay will autoplay the video on your website.

If you are not sure where to add the code then here is a screenshot to help you.

Divi Theme Options jquery code video auto play

The code above mutes the video, sets it to loop and hide the controls on it. If you want to disable looping of the video then you can delete the line number 5 from the code.

jQuery(".lwp-video-autoplay .et_pb_video_box").find('video').attr('loop', 'loop');

And if you want to show controls on the video then you need to remove the line number 11 from the code.

jQuery('.lwp-video-autoplay .et_pb_video_box').find('video').removeAttr('controls');

Leave a comment below if you found this helpful or have any questions. Donโ€™t forget to subscribe to the Newsletter to receive the latest tutorials in your inbox.

About the Author

The author of learnhowwp.com is a WordPress expert with over a decade of experience, specializing in Divi. Since 2014, they have built numerous WordPress sites and developed 8 Divi plugins with over 30,000 active installations. A former support team member at Elegant Themes, they launched learnhowwp.com in 2020 to share their in-depth knowledge of Divi. Now home to over 65+ articles dedicated to Divi tutorials and insights

148 Comments

  1. Brendan

    Hi LearnHowWP,

    I used this fix and it worked perfectly with Google Chrome.
    We have a bit of a unique situation, where we have a video (webM) that has a transparent background that plays on the home page of the website.

    On Chrome the controls were removed, however, the load order causes the default video player to flash and then be removed. I resolved this by adding in the following CSS:

    .kv-butterfly video::-webkit-media-controls {
    display: none;

    However, this did not resolve it on Firefox, and Safari simply does not show anything. The entire video module is hidden.

    Please let me know if you have any fixes or tips.

    Cheers,
    Brendan

    Reply
    • learnhowwp.com

      I am sorry but that is how the code works. It waits for the page to load and then works to hide the controls.

      I will look in to a CSS solution if possible and update the article.

      Reply
  2. Sarathy s

    Did everything as suggested unfortunately not working ๐Ÿ™

    staging 4 . battrx . com

    can you pls help

    Thank you

    Reply
    • learnhowwp.com

      You have a YouTube video on the website. As mentioned in the start of article this code only works for self hosted videos. It does not work for YouTube or Vimeo videos.

      Reply
  3. Joe Velasco

    Thank you for this code. Works like a charm and took less then a couple of minutes to make work. Super excited!

    Question, is there anyway to add code to send the visitor to a new page after the video has played?

    If not I am happy just the way it is!

    Thanks again!!!!

    Reply
    • learnhowwp.com

      You are welcome Joe. Unfortunately there is no quick way to do it that I can think of right now.

      Reply
    • Kenny Holmes

      Hi Joe! Add a redirect script after the video, set the timeout to be right after your video has played or right before. Here is the script that I am using – feel free to modify:

      setTimeout(function(){
      window.location.href = ‘https://yourwebsite.com/redirected-page/’;
      }, 3000);

      Reply
  4. Sasko

    Not work on mobile

    Reply
    • learnhowwp.com

      Can you please go through the other comments about mobiles. It could be related to power saving mode or other settings on mobile.

      Reply
  5. Avery Jones

    Is there a way for it play on all browsers? The video is working in Chrome but in Safari I am just seeing the still image

    Reply
    • learnhowwp.com

      Could you share a link to the page so I can take a look.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Our Plugins Are Already Being Used On 30,000+ Amazing Websites.

We offer a 30 Day Money Back Guarantee on all plugins, so joining is Risk-Free!