Support

Account

Home Forums General Issues Custom Image Sizes Reply To: Custom Image Sizes

  • Say you have selected the field to return image object (which is default).
    Then you actually already have all image sizes when you fetch the field..

    
    <?php 
    $image = get_field('image_field');
    echo $image['url']; //This is the full image
    echo $image['sizes']['medium']; //This is the medium image
    echo $image['sizes']['thumbnail']; //This is the thumbnail image
    echo $image['sizes']['customsize']; //This is a custom sized image
    ?>
    

    So to display an image you’ll do:

    
    <?php $image = get_field('image_field'); ?>
    <?php if($image): //dont output an empty image tag ?>
    <img src="<?php echo $image['sizes']['customsize']; ?>" width="<?php echo $image['sizes']['customsize-width']; ?>" height="<?php echo $image['sizes']['customsize-height']; ?>" alt="<?php echo $image['caption']; ?>" />
    <?php endif; ?>
    

    This will give you an image of a custom size with all the necessery values set for a legit xhtml/html5 markup.
    There’s really no reason for you to change the field to return ID and do the query yourself since it’ll just mean two queries instead of one. The only reason would be if you want to manipulate the image or perhaps fetch some more advanced info in a controlled way.