Home › Forums › Front-end Issues › WordPress 4.4 responsive images › Reply To: WordPress 4.4 responsive images
I found a solution so that ACF creates the correct code from a WYSIWYG field. You only have to add
add_filter( 'acf_the_content', 'wp_make_content_images_responsive' );
to your functions.php. I hope Elliot will add this direct into the code, so that ACF filters the WYSIWYG content like WP does.
For the image field this code works for me:
$image = get_field('my_image');
$img_src = wp_get_attachment_image_url( $image['id'], 'full' ); $img_srcset = wp_get_attachment_image_srcset( $image['id'], 'full' ); ?>
<img src="<?php echo esc_url( $img_src ); ?>"
width = "<?php echo $image['sizes']['Stripe-width']; ?>"
height = "<?php echo $image['sizes']['Stripe-height']; ?>"
srcset="<?php echo esc_attr( $img_srcset ); ?>"
sizes="(max-width: 100vw) 480px" alt="<?php echo $image['alt']; ?>"
>
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.