Support

Account

Home Forums ACF PRO How to user srcset with image ID Reply To: How to user srcset with image ID

  • I have just done this, BUT I have done it in Twig, not in PHP, so you need to rewrite the twig back to php, which should be easy.

    <a href=""><img srcset="' ~ image_320 ~ ' 150w, ' ~ image_640 ~ ' 80w" sizes="(max-width:640px) 150px" src="' ~ image_640 ~ '" /></a>

    ‘ ~ is the same as ‘ . in php.

    image_320 and and image_640 are variables which contain nothing more than the file name.

    If the screen is bigger than 640 px wide, it uses the image_640 and otherwise the image_320.

    Hope this helps a bit.