Home › Forums › Front-end Issues › WordPress 4.4 responsive images › Reply To: WordPress 4.4 responsive images
Again, I’m sure this could be improved upon but here’s what I’ve ended up with.
<?php
$image = get_sub_field('image_field_name');
$imageID = $image['ID'];
echo wp_get_attachment_image( $imageID, 'full', false, array( 'class' => 'lazyload', 'data-sizes' => 'auto' ) );
?>
This works for images that are set to return the image array (this is how all my fields are currently set up). I’ve included the lazysizes jquery plugin (https://github.com/aFarkas/lazysizes) on my site which will lazyload images and update the image’s sizes
attribute to match its container rather that what WordPress seems to be doing by default which seems to be an arbitrary value.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.