Home Forums Add-ons Gallery Field Return Media file not Attachment Page


Return Media file not Attachment Page

  • I have edited the main WP Gallery function to output as a fancybox lightbox gallery, which works fine when I add a gallery to a normal page/post.

    When I add a gallery through the AFC Gallery add-on, clicking a thumbnail returns the attachment page, rather than working as a lighbox.

    Im just using the advised code for the WP Gallery. What do I need to change to return the Media File in the link?

    $image_ids = get_field('gallery', false, false);
    $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';
    echo do_shortcode( $shortcode );
  • I found this here and am not sure how to work it into the code you posted above, but it looks to be a good way to get it to link to the image itself in the fancybox/lightbox.

     $images = get_field('gallery');
      if( $images ):
            <?php foreach( $images as $image ): ?>
                    <a class="fancybox" href="<?php echo $image['url']; ?>">
                         <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                    <p><?php echo $image['caption']; ?></p>
            <?php endforeach; ?>
    <?php endif; ?>

    PS: Edit the above HTML as needed. 🙂

  • Hmm, I’m not sure that helps me. I tried swapping out $image_ids for $images etc but got the same results. I shouldn’t need to alter any HTML. I’ve integrated fancybox into the WP Gallery via my functions.php file, so on normal pages the WP Gallery acts like fancybox right out of the box.

    It’s only when WP Gallery is called using this add-on that clicking a thumbnail opens the attachment page rather than the media file in a lightbox.

    Thanks for your help anyway 🙂 I’ll keep looking…

  • Thanks to James in support for the fix below:

    <?php $image_ids = get_field('gallery', false, false); 
    $shortcode = '[gallery link="file" ids="' . implode(',', $image_ids) . '"]'; 
    echo do_shortcode( $shortcode ); ?>

    Now works like a charm 🙂

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

You must be logged in to reply to this topic.