Home › Forums › Front-end Issues › WordPress 4.4 responsive images › Reply To: WordPress 4.4 responsive images
I have been using a function that bridged ACF and the RICG Responsive Images plugin. I went ahead and adapted that to WP 4.4.
function _acf_ricg_image($image, $alt='', $class = '', $size='full') {
if (!empty($image)) {
if (!$alt) {
$alt = $image['alt'];
}
$url = $image['url'];
if ($size) {
if (isset($image['sizes'][$size])) {
$url = $image['sizes'][$size];
}
}
if (function_exists('wp_get_attachment_image_srcset')) {
$img = '<img src="'. $url . '" srcset="' . wp_get_attachment_image_srcset( $image['id'], $size ) . '" alt="' . $alt . '"';
} else {
$img = '<img src="'. $url . '" alt="' . $alt . '"';
}
if ($class) {
$img .= ' class="' . $class . '"';
}
$img .= ' />';
return $img;
}
}
Then in my template I use:
<?php if (get_field('slide_image')) { echo _acf_ricg_image( get_field('slide_image')); } ?>
There has to be a better way to do it, but I haven’t had time to look into it yet. Will update this thread if I come up with something better.
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.