Home › Forums › Add-ons › Gallery Field › Popup gallery (lightbox etc) › Reply To: Popup gallery (lightbox etc)
@johnw6761 I use a true/false field as enable/disable lightbox / fancybox field. This is no “simple solution” as in “plug-and-play” to implement. You need to register / enqueue the lightbox / fancybox css and js files yourself. Just wrap every image in your gallery loop with an element and the lightbox / fancybox options. If you want a plug-and-play solution, you’re gonna have to search for a plugin or add-on.
If you like to code, it could look something like this:
$output = '<figure' . get_the_attributes($attributes) . '>';
if(is_object($lightbox)) $output .= "<a data-fancybox=\"{$lightbox->id}\" href=\"{$lightbox->href}\" data-srcset=\"{$lightbox->srcset}\">";
if(!empty($options['before'])) $output .= $options['before'];
$output .= wp_get_attachment_image($image_id, $image_size, $is_icon, array('class' => $image_style));
if(!empty($options['after'])) $output .= $options['after'];
if(is_object($lightbox)) $output .= get_the_icon('search') . '</a>';
$output .= '</figure>';
Hope this helps.
Note “get_the_attributes” and “get_the_icon” are not default WP functions.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.