Home Forums Add-ons Repeater Field 2 options for responsive images in repeat field Reply To: 2 options for responsive images in repeat field

  • This is something that I just did recently on a site and it might help you. In my case I wanted the images to be responsive in the same way that images added to the content area are made responsive, so I make WP do the work for me.

    You’ll need to adjust this because I only work with image ID values, but it will give you the idea.

    $image_id = get_field('YOUR IMAGE FIELD', false, false);
    $image_size = 'YOUR IMAGE SIZE'; // set this to the larges image you want shown
    $image = wp_get_attachment_image_src($image_id, $image_size);
    $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
    if (!$image_alt) {
      $image_alt = get_the_title($post->ID);
    $image_tag = '<img src="'.$image[0].'" width="'.$image[1].
                  '" height="'.$image[2].'" alt="'.$image_alt.
                  '" class="size-'.$image_size.
                  ' wp-image-'.$image_id.'" />';
    $image_tag = wp_make_content_images_responsive($image_tag);
    echo $image_tag;

    The important part is setting the class of "wp-image-{$image_id}" which is all that WP uses to add the srcset.