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

Avatar stefano.ulivieri asked

Lightbox on images

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


Avatar thomas.p Support answered

Hi stefano.ulivieri,

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


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

Kind regards


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.