How to get WordPress post featured image url

2019-01-10 02:07发布

I am using a this function to get the featured images

<a href="#" rel="prettyPhoto">
<?php the_post_thumbnail('thumbnail'); ?>
</a>

now i want to get the full featured image on click on anchor tag for which i need a featured image url in

<a href="here" rel="prettyPhoto">

please help

18条回答
Luminary・发光体
2楼-- · 2019-01-10 02:39

You will try this

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID),'full' ); ?>//Here you can manage your image size like medium,thumbnail or custom size
 <img src="<?php echo $url ?>" />
查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-10 02:41

If the post is an image and we already know what the image is. It's possible to get the thumbnail url without too much hassle.

echo pathinfo($image->guid, PATHINFO_DIRNAME);

查看更多
你好瞎i
4楼-- · 2019-01-10 02:41
// Try it inside loop.  
<?php
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo $feat_image;
?>
查看更多
Summer. ? 凉城
5楼-- · 2019-01-10 02:42

This perfectly worked for me:

<?php echo get_the_post_thumbnail_url($post_id, 'thumbnail'); ?>
查看更多
forever°为你锁心
6楼-- · 2019-01-10 02:43

Easy way!

 <?php 
     wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()))
 ?>
查看更多
放荡不羁爱自由
7楼-- · 2019-01-10 02:45

hi i think this is the most easiest solution and the updated one;

<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
查看更多
登录 后发表回答