Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Having trouble linking to the_post_thumbnail WordPress


this is what i currently have:

<a id="single_image" href="<?php the_post_thumbnail('full'); ?>"><?php the_post_thumbnail('home-port'); ?> </a>

the output link doesn't work and this is left above my images: ">

Answers (3)


Andrew Wong answers:

<?php the_post_thumbnail('full'); ?> = Output the whole URL from <img src... >

You need to look for the URL of the post thumb only.

$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); // GET POST THUMBNAIL URL
<a id="single_image" href="<?php echo $url; ?>">
<?php the_post_thumbnail('home-port'); ?>

Daniel Bell comments:

Thanks a lot! Worked like a charm, and thank you for the brief explanation. Voted for you.


Nilesh shiragave answers:

Use this code

$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '<a id="single_image" href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
echo '</a>';


Romel Apuya answers:

try this one:

<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');?>
<a id="single_image" href="<?php echo $src[0]; ?>"><?php the_post_thumbnail('home-port');?></a>