0

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!

2
/*-----------------------------------------------------------------------------------*/
/* 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});
}
  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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