Jump to content

Add Caption to image in masonry grid Squarespace 7.1

Go to solution Solved by Beyondspace,

Recommended Posts

  • Solution
10 hours ago, TanveerSaini said:

Site URL: https://www.jfkjets.com/airport-movements

Hi, i'd like to have the ability to enable captions when someone opens a lightbox.

The page URL is: https://www.jfkjets.com/airport-movements, and I have included an example of one of the images that has a description but the caption won't show up.

Thank you!

Screen Shot 2021-04-03 at 12.10.45 PM.png

You can extract the alt tag of the image to lighbox by doing this

1. Add this snippet into Settings->Advanced->Code Injection->Header

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('.gallery-lightbox-item-img').each(function(){
    var alt = $(this).find('img').attr('alt');
    $(this).append('<div class="lightbox-caption">' + alt + '</div>');
    });
});
</script>

2. Add this to Design->Custom CSS

.lightbox-caption {
    display: block;
    z-index: 9999;
    position: absolute;
    bottom: 0;
    width: 100%;
    text-align: center;
}

image.thumb.png.9889b3e2fdb56e7386f8a2a1469659ff.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date format)
💫 Animated Buttons (Referral URL)
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment
12 hours ago, bangank36 said:

You can extract the alt tag of the image to lighbox by doing this

1. Add this snippet into Settings->Advanced->Code Injection->Header


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('.gallery-lightbox-item-img').each(function(){
    var alt = $(this).find('img').attr('alt');
    $(this).append('<div class="lightbox-caption">' + alt + '</div>');
    });
});
</script>

2. Add this to Design->Custom CSS


.lightbox-caption {
    display: block;
    z-index: 9999;
    position: absolute;
    bottom: 0;
    width: 100%;
    text-align: center;
}

image.thumb.png.9889b3e2fdb56e7386f8a2a1469659ff.png

Hii, thank you, it works really well!! Just one concern, all of the other images have their image titles in them as well (if there's no caption it will show the file name), can we disable that?

Thank you!!!

Link to comment
9 hours ago, TanveerSaini said:

Hii, thank you, it works really well!! Just one concern, all of the other images have their image titles in them as well (if there's no caption it will show the file name), can we disable that?

Thank you!!!

It would be tricky since squarespace takes the image name as alt by default, on other images with proper alt text, is there anything in common? such as the same prefix: Edited by: ??

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date format)
💫 Animated Buttons (Referral URL)
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.