Open YouTube video popup on page load and autoplay then close the popup automatically when the video has finished

Product:

WonderPlugin Lightbox

Tutorial:

This tutorial will guide you how to open a YouTube lightbox popup on page load, play the video then close the popup automatically after the video has finished playing.

Please note, video autoplay does not work mobile and tablet devices, for example, iPhone, iPad and Android.

In your WordPress post or page editor, switch to Text mode, then enter the following code:

<a href="https://www.youtube.com/watch?v=c9-gOVGjHvQ" class="wplightbox" data-width=960 data-height=540 data-autoopen="true" data-autoopendelay=1000 data-autoclose="true">Click to open a YouTube video in a Lightbox</a>

In the above code, the class name class="wplightbox" activates the lightbox on the link.

The data attribute data-width=960 and data-height=540 specify the size of the popup, data-autoopen="true" automatically opens the lightbox on page load, data-autoopendelay=1000 defines the open delay in milliseconds, data-autoclose="true" closes the popup after the video has finished playing.

If you want to hide the lightbox link, you can place the code into a hidden div, for example:

<div style="display:none">
<a href="https://www.youtube.com/watch?v=c9-gOVGjHvQ" class="wplightbox" data-width=960 data-height=544 data-autoopen="true" data-autoopendelay=1000 data-autoclose="true">Click to open a YouTube video in a Lightbox</a>
</div>

To view the online demo, please visit YouTube video popup and auto close demo.