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.
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.