L
L
lorab2022-03-05 19:36:45
WordPress
lorab, 2022-03-05 19:36:45

How to correctly specify image size in ACF?

How can I set my image size in this ACF plugin code (different from the thumbnails that are set in woocommerce? For example: I need this image to be displayed 250*270.

<?php 

$image = get_field('image-descr');
$size = 'thumbnail'; 

if( $image ) {

  echo wp_get_attachment_image( $image, $size );

}

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artemy Zheman, 2022-03-05
@lorab

Option 1.
On a good start, you need to create a new size. Then use this size at the time of output.
add_image_size( 'new-size', 250, 270, true );

$image = get_field('image-descr');
$size = 'new-size'; 
if( $image ) {
  echo wp_get_attachment_image( $image, $size );
}

But, for normal work, you need to regenerate the thumbnails to new sizes, for this you can install the . He will do it all automatically.
Option 2.
Connect this script to your site, and make a conclusion through its function, the size will change on the fly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question