Support

Account

Home Forums General Issues Conditional to use 'full' image size with animated GIFs

Solved

Conditional to use 'full' image size with animated GIFs

  • Hi there,

    I am using ACF and pulling images into my category archives via ‘wp_get_attachment_image_src’ like this:

    <?php $image = wp_get_attachment_image_src(get_field('image'), ‘grid’); ?>
    <img src="<?php echo $image[0]; ?>" alt="" />

    My client will be upoloading animated gifs to this field and I need WordPress to use the ‘grid’ image size if the image is a jpeg, but use ‘full’ if it is a gif, so that we retain the animation.

    How should I go about this? Thanks in advance!

  • Hi @lechatlisse

    You will need to add in a conditional statement with another image load like so:

    
    <?php 
    
    $image = wp_get_attachment_image_src(get_field('image'), 'grid');
    $image = $image[0];
    $ext = pathinfo($image, PATHINFO_EXTENSION);
    
    if( $ext == 'gif' )
    {
    	$image = wp_get_attachment_image_src(get_field('image'), 'full');
    	$image = $image[0];
    }
    
    ?>
    <img src="<?php echo $image; ?>" alt="" />
    

    Hope that helps.

    Thanks
    E

  • That does help! You’re amazing Elliot, thank you!

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

The topic ‘Conditional to use 'full' image size with animated GIFs’ is closed to new replies.