I'm using .mp4 video in widget as an alternative for GIF to speed up my load time. My question is, how can I make the video autoplay and looping without using a plugin?

  • lots of browsers have restrictions on when videos can autoplay and loop, e.g. videos with audio can't autoplay on most browsers, even if the audio track is silent
    – Tom J Nowell
    Apr 28, 2022 at 16:22

1 Answer 1


You can do that by writing JavaScript. Like, in your theme footer (footer.php) if you place code like below (before the ending </body> tag):

    var vid = document.querySelector('video.wp-video-shortcode');
    vid.autoplay = true;

It will autoplay all the videos of all the video widgets on the DOM (or in fact all the videos with the <video class="wp-video-shortcode"></video> tag). I just tested with the WordPress Video widget with a YouTube video.

If you want to autoplay only a certain video, then you have to use the id (#id) of the <video> element.

For the looping, you can consult this thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.