Home › Forums › ACF PRO › Custom gallery image link › Reply To: Custom gallery image link
Had the same query and stumbled on this page.
I found a solution that works perfectly for anyone else that ends up here.
1. Create a new ACF Field Group e.g. “Media Metadata”
2. Add a field as a Link or Page Link or URL (I used Page Link)
3. Then under Location => Rules “show this field group if” = Attachment
4. This will add a new link field into each media library item
(https://www.greengeeks.com/tutorials/article/add-custom-fields-to-media-wordpress/)
I used a Page Link and added links to my Media in the Media Library.
So when calling it in my Gallery loop code:
<?php
foreach( $images as $image ):
$link_id = get_post_meta( $image['id'], 'page_link', true); ?>
<a href="<?php the_permalink( $link_id ); ?>" title="<?php echo $image['alt']; ?>">
<img data-src="<?php echo $image['sizes'][$size]; ?>"/></a>
<?php
endforeach;
?>
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.