Gallery ACF Code - Brown Surfing

Gallery ACF Code

Posted on: January 28th, 2022
By: Efrain Lemus

Here’s an example of how I commonly style the ACF gallery. This is for use in a PHP template, however, you can use it in HTML by taking the PHP code out.

Here’s the support article from Advanced Custom Fields themselves.

$gallery = get_field('portfolio','options');
if( $gallery ): 
foreach( $gallery as $image ):
echo '<div class="col-lg-3 col-md-4 col-6 col col-portfolio mt-3 mb-3 overflow-h">';
echo '<div class="position-relative">';
echo '<a href="' . wp_get_attachment_image_url($image['id'], 'full') . '" data-lightbox="image-set">';
echo wp_get_attachment_image($image['id'], 'full','',['class'=>'w-100 img-portfolio'] );
echo '</a>';
echo '</div>';
echo '</div>';
endforeach; 
endif;

Have any questions or comments? Write them below!


Leave a Reply

Your email address will not be published.