Add attachment field value to img markup

In the ACF documentation, they explain how to go about “Adding Fields to Media Attachments“. Can anyone suggest how to use those fields to alter the image tag markup?

I’ve added two fields: credit_name (photographer’s name) and credit_website (URL of the photographer’s website) to media attachments. I have searched for ways to display the values of those fields near the image but can’t find a working solution.

One option that I could make work, using javascript, would be to add data-image-name and data-image-website attributes to the img tag, but I can’t figure out how to do that.

Hooking into wp_get_attachment_image_attributes works for the Featured Image but not for inline images!

The solution found here:
https://allisontarr.com/2018/02/12/acf-custom-field-media-item/
works by piggy-backing the ACF field values on the image caption. It works, but it is sloppy and doesn’t work if the image has no other caption.

Any suggestions would be much appreciated!

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer