Support

Account

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.