Skip to content

Instantly share code, notes, and snippets.

@eliasfaical
Forked from crondeau/ACF-img-size
Created June 13, 2018 15:11
Show Gist options
  • Save eliasfaical/e3ad4b269ee942f4b5401d5a2ad45287 to your computer and use it in GitHub Desktop.
Save eliasfaical/e3ad4b269ee942f4b5401d5a2ad45287 to your computer and use it in GitHub Desktop.
Display different image size using ACF
//To display an image using ACF, one would set the image custom field to image url and call the img as follows:
<?php if( get_field( 'field_name' ) ): ?>
<?php while( has_sub_field( 'field_name' ) ): ?>
<img src="<?php the_sub_field( 'image' ); ?>" alt="">
<?php endwhile; ?>
<?php endif; ?>
// To display a different size, ie. thumbnail, medium, large or custom size you can use the following:
<?php if( get_field( 'field_name' ) ): ?>
<?php while( has_sub_field( 'field_name' ) ): ?>
<?php $image = wp_get_attachment_image_src( get_sub_field( 'image' ), 'image_size' ); ?> //change this to whatever size you want
<img src="<?php echo esc_url( $image[0] ); ?>" alt=""> // Make use you have images set to image ID in the ACF option
<?php endwhile; ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment