Getting it to work with all images in a WordPress theme
See original GitHub issueHey
I like the lightbox you have created! I am working on using the correct code to add this to my child theme functions.php file. It would be great to have it work with WordPress. I will also add it to my article on using lightboxes without using a plugin: http://easywebdesigntutorials.com/adding-a-lightbox-to-wordpress-without-using-a-plugin/ (An article still being shaped.)
What I got right now based on earlier code used with Colorbox, Nivo and Fluidbox (more or less functioning. It looks best with Colorbox. Not that the site is working with it right now though. I am creating an update that I will add onto the site).
I want to get it working with Lightbox 2. It would also help whomever else is looking for the same thing.
What is off with the following code? Could you add the code to get it working with WordPress? Btw are there some settings on can adjust to customize the lightbox further?
/\* Enqueue lightbox 2 - http://lokeshdhakar.com/projects/lightbox2/ */
add_action( 'wp_enqueue_scripts', 'enqueue_lightbox2' );
function enqueue_lightbox2() {
wp_enqueue_style( 'lightbox2-css', get_bloginfo( 'stylesheet_directory' ) . '/lightbox2/css/lightbox.css', array(), CHILD_THEME_VERSION );
wp_enqueue_script( 'lightbox2', get_bloginfo( 'stylesheet_directory' ) . '/lightbox2/js/lightbox.min.js', array( 'jquery' ), '2.7.1' );
wp_enqueue_script( 'lightbox2-init', get_stylesheet_directory_uri() . '/lightbox2/lightbox2-init.js', array( 'lightbox2' ), '1.0.0', true );
}
I then made the init.js file:
jQuery(function( $ ){
$("a[href$='.jpg'],a[href$='.png'],a[href$='.gif']").lightbox2();
$('a.gallery').lightbox2();
});
Have a great day!
Issue Analytics
- State:
- Created 9 years ago
- Comments:14 (1 by maintainers)
Top GitHub Comments
I made for my wordpress theme following: in functions.php file:
thank you all! This thread was helpful. I migrated a site to WP that was previously using Lightbox2, and I really prefer Lightbox2 to the others I’ve tried so I’m glad I could get it working. In case anyone else stumbles on this thread, here’s what I did: