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

  • SOLVED

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)

2011-08-14

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.

<?php
$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'); ?>
</a>


Daniel Bell comments:

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

2011-08-14

Nilesh shiragave answers:

Use this code


<?php
$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') . '" >';
the_post_thumbnail('home-port');
echo '</a>';
?>

2011-08-14

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>