Home › Forums › General Issues › adding a custom field to media attachment › Reply To: adding a custom field to media attachment
I have not tested this all out but it should work for you.
With a custom field image
<?php $image = get_field('image'); $custom_image_url = get_field('customURL', $image['ID']);?> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" data-attr="<?php echo $custom_image_url;?>" />
With a featured image
<?php $url = get_the_post_thumbnail_url( $post->ID ); $thumbnail_id = get_post_thumbnail_id( $post->ID ); $custom_image_url = get_field('customURL', $thumbnail_id); $alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true); ?> <img src="<?php echo $url; ?>" alt="<?php echo $alt;?>" data-attr="<?php echo $custom_image_url;?>" />
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.