Home › Forums › Add-ons › Gallery Field › Conditional to use animated gif in gallery › Reply To: Conditional to use animated gif in gallery
Yup, you can definitely utilize similar conditional logic. The only thing that might affect it is that the size of your GIF could be way off from the size of the other images so you might need to regular that on the ACF upload end to make sure your user is uploading something of similar width/height.
<?php
$images = get_field( 'gallery' );
$size = 'thumbnail';
if ( $images ) : ?>
<ul>
<?php foreach ( $images as $image ) :
$url = $image["filename"];
$filetype = wp_check_filetype( $url );
if ( 'gif' == $filetype['ext'] ) {
$url = $image['url'];
} else {
$url = $image['sizes'][$size];
} ?>
<li><img src="<?php echo esc_url( $url ); ?>" alt="Text describing my image here" /></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
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.