GithubHelp home page GithubHelp logo

temsool / elementor-loop-dynamic-lightbox Goto Github PK

View Code? Open in Web Editor NEW

This project forked from antoanst/elementor-loop-dynamic-lightbox

0.0 0.0 0.0 7 KB

A workaround for opening dynamic YouTube links in a lightbox in Elementor Loops.

elementor-loop-dynamic-lightbox's Introduction

Elementor Loop Dynamic Lightbox

A workaround for opening dynamic video links in a lightbox in Elementor Loops. Useful, because the lightbox functionality in Elementor doesn't include the option to add dynamic data, such as data from ACF custom fields.

As of November 2023, Elementor's native elementorFrontend.utils.lightbox.showModal method is unavailable, requiring a 3rd party lightbox.

Prerequisites

  • A Custom Post Type with an ACF URL Custom Field for video links (e.g., YouTube links).
  • Elementor Pro with Loop functionality.

Setup Instructions

1. Configure Your Loop

Edit your loop to include an element that acts as a link. This could be a text block, image, or the loop container itself.

To setup the loop container as a link:

  • Go to Layout > Additional Options > HTML Tag and select a (link).
  • Ensure the loop item contains no other links.

Add the links:

  • Use the dynamic tags feature (database icon) to insert the ACF URL Custom Field which contains your video link.

2. Add the Required Class

Assign the class js-video-lightbox to the element with the link.

  • Navigate to Advanced > CSS Classes and input js-video-lightbox.

3. Insert Custom Script

Go to Elementor > Custom Scripts and add the following JavaScript code:

<script>
jQuery(document).ready(function($) {
    $('a.js-video-lightbox').on('click', function(e) {
        e.preventDefault(); // Prevents default link action
        $(this).magnificPopup({
            type: 'iframe'
        }).magnificPopup('open');
    });
});
</script>

Set display conditions to include only pages where this script is needed to optimize loading speeds.

4. Load Magnific Popup Library

Include the Magnific Popup library by adding the following code to your theme's functions.php file:

function enqueue_magnific_popup() {
    wp_enqueue_style('magnific-popup-css', '//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css');
    wp_enqueue_script('magnific-popup-js', '//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js', array('jquery'));
}
add_action('wp_enqueue_scripts', 'enqueue_magnific_popup');

elementor-loop-dynamic-lightbox's People

Contributors

antoanst avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.