How to add a button on top of the Wonder Lightbox to redirect to a webpage


Wonder Lightbox


This tutorial will guide you how to add a button on top of the lightbox created with Wonder Lightbox, and clicking the button will redirect to another page.

To add a button on top of the lightbox, you can add the following JavaScript code to the same page as the lightbox link.

  $(document).ready(function() {
    $(window).on("html5lightbox.lightboxopened", function() {
      var btn = "<a style='position:absolute;top:24px;right:24px;' href=''><button class='redirectbtn'>Skip</button></a>";

If you don't know how to add the JavaScript code to the webpage, in your WordPress dashboard, left menu Wonder Lightbox -> Lightbox Options, Advanced Options, you can add the code to the Custom JavaScript input box. Please note, if you add the JavaScript code to this input box, it will add the button to all lightboxes on the website.

The code will add a button "Skip" on the top right corner of the lightbox, clicking it will redirect to the URL defined in the code.

An online demo is as follows: Video Lightbox with Skip Button.

The button has a CSS class name redirectbtn, you can customise the CSS style in your WordPress theme or replace the CSS class to your own class name.