Home Forums Add-ons Gallery Field Linking from the Gallery field to a page


Linking from the Gallery field to a page

  • Hi,

    So i have a gallery field setup with some images in them. I want those images to be links to other pages on my site.

    I made a new custom field group called link to add a custom link field for my images in the edit screen. The custom field shows up and shows me the pages i can link to. So far so good. But for some reason the links to other pages don’t work and when i look into the source code it says <a href=""
    I used the <?php the_field(‘link’); ?> code in my template but this is not working. I placed the code like this:

    <div class="opdrachtgevers">
    			<?php $images = get_field('opdrachtgever'); if( $images ): ?>
                <?php foreach( $images as $image ): ?>
                <a href="<?php the_field('link'); ?>" rel="gallery" title="<?php echo $image['title']; ?>" alt="<?php echo $image['title']; ?> <?php echo $image['caption']; ?>"><img src="<?php echo $image['url']; ?>"/>
                  <?php echo $image['caption']; ?>
                <?php endforeach; ?>
                <?php endif; ?>

    I also tried using the get_field code but that doesn’t work either.
    Am i using the code in the wrong way? I’m not that into php coding.


  • Hi @kwebbin

    So close! All you need to do is target the attachment when using the_field(‘link’) like this:

    <a href="<?php the_field('link', $image['id']); ?>"


  • Great! Thanks alot Elliot, saved me alot of headaches!

  • Hey there,

    Just a quick question, how do I link each image in a gallery to a different page?

    Kind regards

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Linking from the Gallery field to a page’ is closed to new replies.