Home › Forums › General Issues › Using ACF field as Image Caption › Reply To: Using ACF field as Image Caption
Hi @davidzack,
Yup, you’re right – you can utilize img_caption_shortcode
! The example from the WordPress codex is a good skeleton structure to work off of to add the markup you’d like to.
Something to keep in mind is that you’ll need to pass a second parameter when getting your photo_credit
field to target the media it is attached to.
One way of getting the appropriate ID is to use preg_match & regex to split the number off before the $attr
are defined in that example:
preg_match( '/(\d+)$/', $attr['id'], $matches );
$media_id = $matches[1];
$credit = get_field( 'your_field_name', $media_id );
From there you can add conditionals how you’d like & place it where you’d like within your markup. Let me know how it pans out!
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.