YOOtheme Pro is here! The best WordPress and Joomla theme. Learn more

Avatar stefano.ulivieri asked

Lightbox on images

Hi,
i'm trying to apply the uk-lightbox to all image inside a post.
i disabled the thumbnails wordpress generation

i'm trying to add an empty <a> tag around the <img> tag and then adding the uk-data-lightbox to the <img> tag

so, i tried this code:

$(function() {
$("img").each(function() {
$(this).wrap("<a href='#' />");
$("img").attr('uk-lightbox', '');
});
});

but it doesn't work

i'm not very good with Jquery...

  • WordPress
  • UIkit
  • YOOtheme Pro

2 Answers

1

Avatar thomas.p Support answered

Hi stefano.ulivieri,

the syntax is not correct. Please see jQuery wrap() Method.

Example:

jQuery(function() {  
    jQuery("img").each(function() {  
        jQuery(this).wrap(function(){  
              return '<a href="#" /></a>'  
        });  
    });  
});

Kind regards
Thomas

0

Avatar stefano.ulivieri answered

Thanks you thomas!

it's works now, you're right.

i change idea and try to make the lightbox work adding the attribute in a div:

return '<div uk-lightbox><a href="" /></a></div>'

but i got the ligthbox empty (black lightbox with a lighting icon in the center)

i suppose i've to make jquery took the image path and not using return

Know someone who can answer? Share a link to this question via email or twitter.