Support

Account

Home Forums General Issues How to use custom image sizes

Solving

How to use custom image sizes

  • Hi,

    When using flexible content, is it possible to use image sizes? All of the images I upload are full size on the front-end and super slow to load.

    See code:

    <?php elseif(get_row_layout() == 'text_and_image'): ?>
    <section class="content">
    	<div class="row">
    		<div class="columns medium-6">
    			<h2><?php echo get_sub_field('title'); ?></h2>
    			<?php echo get_sub_field('text'); ?>
    		</div>
    
    		<div class="columns medium-6">
    			<img src="<?php echo get_sub_field('image'); ?>">
    		</div>
    	</div>
    </section>

    As an example, I would like this image: <img src="<?php echo get_sub_field('image'); ?>"> to be 600px x 600px?

    Thanks,
    Dan

  • When returning the URL, ACF will only return the URL of the original image.

    You need to either return the image array from the image field so that you have more to work with, the documentation includes information on doing this https://www.advancedcustomfields.com/resources/image/

    or you need to return the image ID can get the image size you want using wp_get_attachment_image_src() https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

  • You can also try defining different image sizes in the Settings-> Media and using that with echo wp_get_attachment_image($image_id, 'large'); or something like that. I usually use the image array and grab the ID from that.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘How to use custom image sizes’ is closed to new replies.