-
-
Save eliasfaical/e3ad4b269ee942f4b5401d5a2ad45287 to your computer and use it in GitHub Desktop.
Display different image size using ACF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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