Support

Account

Home Forums Add-ons Gallery Field Custom class for images in gallery field

Helping

Custom class for images in gallery field

    • Donwey

    • June 27, 2018 at 8:05 pm

    Hi, Is it please possible to add custom class to certain images in gallery field? Is there a simple solution to this please? Thank you

    • vanmar

    • July 27, 2018 at 8:16 am

    This seems relatively tricky.

    One way would be to use the Caption or Description meta box in the Image Uploader to store a class name, and then output it like this

    <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" class="<?php echo $image['caption']; ?>"/>

    Or you could output a generic class for all images

    <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" class="gallery_images_class"/>

    and then use a css :nth-of-type selector to target specific instances (eg. images 4, 7 out of 10)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.