I need to get the URL for Custom post type Thumbnail and assign it to

the_post_thumbnail('', array('class' => 'group1 img-responsive',
                             'href' =>get_permalink($thumbnail->ID)));

at this code

$args = array( 'post_type' => 'sunglassesCPT', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$meta = get_post_custom($post->ID);
   echo '<div class="col-sm-6 col-md-4">';
echo '<div class="thumbnail text-center">';
the_post_thumbnail('', array('class' => 'group1 img-responsive', 'href' =>get_permalink($thumbnail->ID)));
echo '<div class="caption">';
echo '<h4 class="product-title">'.the_title().'</h4>';
echo '<div class="ptitle"><p class="price">'.$meta['my_meta_box_text'][0]. '</p></div>';
echo '<p><a href="#" class="btn btn-sm btn-brown" role="button">Quick View</a></p>';
echo '</div>';
echo '</div>';
echo '</div>';

but this not linking to the image. Can you please let me know what I am doing wrong?

1 Answer 1


The href attribute you are passing under the_post_thumbnail() is incorrect. Note that this attribute is applied to the img tag which obviously doesn't supports href attribute.

It would be better to wrap the_post_thumbnail() with an <a> tag. So it will look something like the following:

echo '<a href="' . get_permalink( $thumbnail->ID ) . '">' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'class' => 'group1 img-responsive' ) ) . '</a>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.