Support

Account

Home Forums Front-end Issues Cannot get srcset to output anything Reply To: Cannot get srcset to output anything

  • Hm, I’ve tried this. Re-uploaded my images but still only 1 size is being output in the sizes attribute

    Isn’t $image_size = ‘project-full’; effectively saying to use only that image size?

    Seems to be the same thing happening with this function:

    function awesome_acf_responsive_image($image_id,$image_size,$max_width){
    
    	// check the image ID is not blank
    	if($image_id != '') {
    
    		// set the default src image size
    		$image_src = wp_get_attachment_image_url( $image_id, $image_size );
    
    		// set the srcset with various image sizes
    		$image_srcset = wp_get_attachment_image_srcset( $image_id, $image_size );
    
    		// generate the markup for the responsive image
    		echo 'src="'.$image_src.'" srcset="'.$image_srcset.'" sizes="(max-width: '.$max_width.') 100vw, '.$max_width.'"';
    
    	}
    }