Lity Lightbox for WordPress

Copy the „Lity“ folder in plugin folder and the name folder „lity“.

Import stylesheet in header

<link href="/wp-content/plugins/lity/dist/lity.css" rel="stylesheet">

Import JS

<script src="/wp-content/plugins/lity/vendor/jquery.js"></script>
<script src="/wp-content/plugins/lity/dist/lity.js"></script>

Download Lity, extract and put it in the „Plugins“ folder

Close Lity Lightbox on browser back button


$(document).on('lity:open', function () {
    if (location.hash === '#lity') {
        return;
    }
    history.pushState({}, '', '#lity');
});

$(document).on('lity:close', function () {
    if (lity.current()) {
        return;
    }
    history.replaceState({}, '', location.href.split('#')[0]);
});

$(window).on('hashchange', function () {
    if (!location.hash && lity.current()) {
        lity.current().close();
    }
});