I think it would be possible to parse the HTML from the editor on load and replace the image tag with one that includes srcset, but that seems like a poor solution. In addition to being a pain to code, you probably don’t want a preg_replace running every page load on every WYSIWYG field.
Hopefully ACF issues an update that will start including srcset in img tags when they are added to the WYSIWYG editor on the admin side.
Regarding your snippet above, I would return the image ID instead of array whenever possible. Again, per Joe McGill’s recommendation, it will be faster. Not the end of the world, but if possible might as well speed it up.
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!
© 2022 Advanced Custom Fields.