I am trying to add the featured image url to the featured image, so it will open up in a lightbox when clicked.
My code is:
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<a href="#" target="_blank"><?php if ( has_post_thumbnail() ) { the_post_thumbnail();} ?></a>
<?php endwhile; ?>
<?php else: ?>
<article>
<h1><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>
</article><!--/ Article -->
<?php endif; ?>
I have tried quite a few things but cannot get it to pull the thumbnail URL. I have tried adding these to where the link # is:
wp_get_attachment_thumb_url( get_post_thumbnail_id( $post->ID ));
…
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
…
<?php echo $thumbnailsrc ?>
I am sure there is a simple solution that I am yet to find. Thanks to anyone who maybe able to assist 🙂
please try this code adding in to your post loop. and confirm you have set feature image for that post which you listings.
Try this:
wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' )[0]
Assuming you are in The Loop, you can simply use
get_post_thumbnail_id()
to get the current post featured image ID. You also need to pass the second parameterfull
in order to get the non-resized version of the image for your lightbox source. You can limit it to large as well, if you like.