Support

Account

Home Forums General Issues Adding Srcset to Image Size choice is it possible

Solving

Adding Srcset to Image Size choice is it possible

  • In another thread which I got some help with, I added the ability to add an image size to a loop that works great. (So the user can choose which image size they want ) I’m wondering tho is there a way add the srcset into that somehow so that the selected image has the srcset attribute?

    This is the code I have that works perfect except for that it returns the image without the srcset:

    <?php if ( have_rows( 'image' ) ): ?>
            <?php while ( have_rows( 'image' ) ) : the_row(); ?>
                <?php if ( get_row_layout() == 'image_or_graphic' ) : ?>
                    <?php $image_choice = get_sub_field( 'image_choice' ); ?>
                    <?php if ( $image_choice ) { ?>
                        <img class="<?php the_sub_field('css_class') ?>" src="<?php 
        echo $image_choice['sizes'][get_sub_field('image_size')]; ?>" alt="<?php 
        echo $image_choice['alt']; ?>" />
                    <?php } ?>
                    
                <?php endif; ?>
            <?php endwhile; ?>
        <?php else: ?>
            <?php // no layouts found ?>
        <?php endif;  ?>

    Maybe it’s not possible but trying to figure it out 🙂
    THANK YOU

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

You must be logged in to reply to this topic.