Created
September 15, 2015 15:33
-
-
Save n7studios/d1705305f783603b8c86 to your computer and use it in GitHub Desktop.
Envira Gallery - Load Lightbox from Link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Envira Gallery - Load Lightbox from Link | |
* Plugin URI: http://enviragallery.com | |
* Version: 1.0 | |
* Author: Tim Carr | |
* Author URI: http://www.n7studios.co.uk | |
* Description: Launch a gallery's lightbox from a link. Requires that the gallery be embedded into the Page. | |
*/ | |
function envira_gallery_launch_lightbox( $data ) { | |
?> | |
<script> | |
jQuery(document).ready(function($) { | |
$('.envirabox').on('click', function(e) { | |
e.preventDefault(); | |
$('.envira-gallery-'+$(this).data('envira-gallery-id')).envirabox().click(); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
add_filter( 'wp_footer', 'envira_gallery_launch_lightbox' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
1. Change data-envira-gallery-id to the Gallery ID you want to display | |
2. Ensure that Gallery is on the same page as the below link | |
3. Ensure the PHP file above is located in wp-content/plugins and activated via WordPress Admin > Plugins | |
--> | |
<a href="#" class="envirabox" data-envira-gallery-id="1234">Load Gallery in Lightbox</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps Envira changed something; your code did not work for me. It would pop up the last image of the gallery, instead of the first. I had to do the following:
$('#envira-gallery-'+$(this).data('envira-gallery-id')+' > div:first-child a').envirabox().click();