Home Forums Add-ons Repeater Field How to optimize images displayed by the_sub_field Reply To: How to optimize images displayed by the_sub_field

  • From the looks of that code you’re not actually calling any ACF functions at all? For example, if your images are set within a repeater field then you should be using get_sub_field() to grab either the image object, Image ID or Image URL. I would recommend setting your image field within your repeater to use image object as that gives you the most flexibility.

    If it was me, I would do the following. I’ve assumed that the code to initialise and stop the repeater come before and after this chunk of code). I am also running under the assumption that you have set your image field to use the image object and that you have set an image thumbnail size in your functions.php file e.g. add_image_size( ‘my-thumbnail’, 240, 240, true );

       $image - get_sub_field('my_image_sub_field_name');
       echo '<img src="'.$image['sizes']['my-thumbnail'].'" />';
    <div class="project-description">
       <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
       <p class="meta-info"><?php echo get_the_term_list( $post->ID, 'locations', '', ', ', '' ); ?></p>
       <a href="<?php the_permalink(); ?>" class="et-zoom"><?php esc_html_e( 'Read more', 'Vertex' ); ?></a>