Support

Account

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; ?>