Created
July 5, 2017 05:27
-
-
Save kristarella/c7a6d8fa2c6f735a33bef2eb15671c82 to your computer and use it in GitHub Desktop.
Activate prettyPhoto on WordPress images, even when image URLs have a query string.
This file contains 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
jQuery(document).ready(function(){ | |
/*-----------------------------------------------------------------------------------*/ | |
/* 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 ( '' !== imageTitle ) { | |
jQuery( this ).attr( 'title', imageTitle ); | |
} | |
if ( jQuery( this ).parents( '.gallery' ).length ) { | |
var galleryID = jQuery( this ).parents( '.gallery' ).attr( 'id' ); | |
jQuery( this ).attr( 'rel', 'lightbox[' + galleryID + ']' ); | |
} else { | |
jQuery( this ).attr( 'rel', 'lightbox' ); | |
} | |
}); | |
jQuery( 'a[rel^="lightbox"]' ).prettyPhoto({social_tools: false}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment