i’m stumped. Firstly this is a Fancybox installed on theme, not a plugin, secondly – i’m still learning – so would super appreciate the help!

Fancybox needs a href link to open/load the images in wordpress post.

I am using “get attached media” to get all images on the post.

Where and how can I create the href link for Fancybox to work within this?

This is the code I am using:

<div class="img_div">

<?php $media = get_attached_media( 'image', $post->ID );
if(! empty($media)){
foreach ( $media as $attachment ) {
    $full = wp_get_attachment_url( $attachment->ID );
    echo '<img class="image-2" data-fancybox="images" src="'.$full.'" alt="'$attachment->post_title'" />';

And this this the Fancybox documentation:

<a href="image.jpg" data-fancybox="images" data-caption="My caption">
<img src="thumbnail.jpg" alt="" />

Any help would be amazing…i’m stumped on this part of the learning curve.

Read more here: Fancybox coding in WordPress – link for images


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: