Skip to content

Instantly share code, notes, and snippets.

@kristarella
Created July 5, 2017 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristarella/c7a6d8fa2c6f735a33bef2eb15671c82 to your computer and use it in GitHub Desktop.
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.
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