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.

My Wordpress theme (when enabled) overrides the rel value of the link of all images with rel="lightbox" using the following code:

http://pastebin.com/Bsh739QY

How can I edit the JQuery to check for the rel value first? If the rel value is already set to "lightbox[xyz123]" or "lightbox[xyz-123|abc]" or "lightbox", then the rel value will not be over-written.

Thanks!

share|improve this question

1 Answer 1

up vote 2 down vote accepted
/*-----------------------------------------------------------------------------------*/
/* Add rel="lightbox" to image links if the lightbox is enabled */
/*-----------------------------------------------------------------------------------*/

if ( jQuery( 'body' ).hasClass( 'has-lightbox' ) && ! jQuery( 'body' ).hasClass( 'portfolio-component' ) ) {
        jQuery( 'a[href$=".jpg"], a[href$=".jpeg"], a[href$=".gif"], a[href$=".png"]' ).each( function () {
                var imageTitle = '';
                if ( jQuery( this ).next().hasClass( 'wp-caption-text' ) ) {
                        imageTitle = jQuery( this ).next().text();
                }
              ;
               if (jQuery(this).attr('rel').indexOf("lightbox") == -1 )
               {
                jQuery( this ).attr( 'rel', 'lightbox' ).attr( 'title', imageTitle );
                }
        });

        jQuery( 'a[rel^="lightbox"]' ).prettyPhoto({social_tools: false});
}
share|improve this answer
    
Thank you for the quick response. It works. However, I needed to change the operator "!=" to "=" first –  JK Thng Aug 22 '12 at 13:15
    
ofcourse...my mistake.. ... -1 means it doesn't have lightbox. Edited my response, and welcome to WPSE –  woony Aug 22 '12 at 13:39

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.