Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I got a theme that has lightbox built in, but only for galleries and featured images, not single images.

It just needs to have class="lightbox" added to the images source. I'd like a simple function that will include this automatically.

Not sure why the author left this out.

share|improve this question
add comment

1 Answer

One way you can accomplish it is this way:

functions.php

add_action( 'wp_enqueue_scripts', 'your_lightbox_callback' );
function your_lightbox_callback(){

    if( is_single() /* or whatever here */ ) {
        wp_register_script( 'your-lightbox', get_bloginfo( 'template_url' ) . '/lightbox-class.js' );
        wp_enqueue_script( 'your-lightbox' );
    }

}

lightbox-class.js

var $j = jQuery.noConflict();
$j( document ).ready( function() {

    $j( '#whereveryourpostsare img' ).addClass( 'lightbox' );

} );

Let me add that this hasn't been tested, just typed here on the fly. If you try it do tell me if you have any issues, thanks!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.