This function is what I’m using to obtain the featured images:
<a href="#" rel="prettyPhoto"> <?php the_post_thumbnail('thumbnail'); ?> </a>
Now I need a featured image URL in order to obtain the complete featured image when I click on the anchor tag.
<a href="here" rel="prettyPhoto">
What can I do about it?
Asked by ManpreetSandhu
Please test the code below and let me know if it works.
<?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> <div id="custom-bg" style="background-image: url('<?php echo $image; ?>')"> </div> <?php endif; ?>
Answered by swapnesh
If you only want the source and not an array of extra data, type:
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?> <img src="<?php echo $url ?>" />
Answered by LOLapalooza
// Try it inside loop. <?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $feat_image; ?>
Answered by Omprakash Patel
<?php wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())) ?>
Answered by Luis Felipe Barnett V
This worked well for me:
<?php echo get_the_post_thumbnail_url($post_id, 'thumbnail'); ?>
Answered by maxim
Post is based on https://stackoverflow.com/questions/11261883/how-to-get-wordpress-post-featured-image-url