Multi Image Field - show alt tag as text

Nice idea.

Inside the lightbox add title header (or text)

image

Scope Add a class for the list
images in this example
(Otherwise the code will affect other elements)
image

Before body

Copy paste this code

<script>
$(function() {
    $('.images img').each(function () {
      var caption = ($(this).attr('alt'));
      $(this).next().text(caption);
    });
});
</script>

Parts of the code:

  • $('.images img').each(function () { loop throw all img inside .images class
  • var caption = ($(this).attr('alt')); get the alt from each image and store this alt inside var
  • $(this).next().text(caption); Change next() dom element (Related to this image element) text() (text docs) to “caption” (The var)

Publish the site - Result:
image

Before:

After:

10 Likes