Viewing 2 replies - 1 through 2 (of 2 total)
  • Assuming you are using the object method of serving the image, specified here https://www.advancedcustomfields.com/resources/image/ Just ammend the code example given by ACF, to include the srcset function:

    Original code:

    <?php 
    
    $image = get_field('image');
    
    if( !empty($image) ): ?>
    
    	<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    
    <?php endif; ?>

    With this plugin’s srcset function:

    <?php 
    
    $image = get_field('image');
    
    if( !empty($image) ): ?>
    
    	<img src="<?php echo $image['url']; ?>" <?php echo tevkori_get_srcset_string( $image['id'], theLargestImageSizeNeeded ); ?> alt="<?php echo $image['alt']; ?>" />
    
    <?php endif; ?>

    theLargestImageSizeNeeded is the name of your image size, e.g. medium/large.

    Untested, but this should work.

    Thread Starter coreybruyere

    (@coreybruyere)

    Yup that was it, didn’t think about getting the ID from the image object.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Advanced Custom Fields’ is closed to new replies.