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

    I used a Page Link and added links to my Media in the Media Library.
    So when calling it in my Gallery loop code:

    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>