Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Created January 21, 2019 15:13
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 pixelbart/8a35df2591bcbfded94f6a062a7b5a01 to your computer and use it in GitHub Desktop.
Save pixelbart/8a35df2591bcbfded94f6a062a7b5a01 to your computer and use it in GitHub Desktop.
Uikit lightbox on wordpress block galleries
(function($) {
if( $('.wp-block-gallery, .wp-block-image').length ) {
$(ukLightboxGallery);
}
function ukLightboxGallery() {
$('.wp-block-gallery, .wp-block-image').attr('data-uk-lightbox', true);
$('figure').each(function() {
var src = $(this).find('img').attr('src');
var alt = $(this).find('img').attr('alt');
if( $(this).find('figcaption').length > 0 ) {
alt = $(this).find('figcaption').text();
}
if( $(this).find('a').length > 0 ) {
$(this).find('a').attr('data-caption', alt);
}
else {
$(this).find('img').wrap('<a href="'+src+'" data-caption="'+alt+'">');
}
});
}
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment