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 );
<li> <?php $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> </div> </li>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.