Define the custom size in functions.php
// ========================================================================= // ADD CUSTOM IMAGE SIZE // ========================================================================= add_image_size( 'gallery-thumb', 600, 400, array( 'left', 'top' ) ); // Hard crop left top
Single line solution
<?php echo wp_get_attachment_image_src( get_field('field_name'), 'medium' )[0]; ?>
With bootstrap card and variables
<?php $attachment_id = get_field('image'); $size = 'gallery-thumb'; $image = wp_get_attachment_image_src( $attachment_id, $size )[0]; ?> <div class="col-md-3"> <div class="card"> <div class="card-img-top"> <a href="<?php the_field('link'); ?>"> <img src="<?php echo $image; ?>" alt="<?php the_field('title'); ?>"> </a> </div> <div class="card-body"> <h4 class="card-title"><?php the_field('title'); ?></h4> </div> </div> </div>
Leave a Reply