WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've enabled my theme with the ability to display the "Featured Image" for the post. However, I'm trying now to determine (1) How to assign a hyperlink to the image and (2) How to call the_post_thumbnail() so that it wraps the hyperlink around the image.

I can't find where this is supported in the current release of WP, but I'm thinking that I must just be missing something.

<div class="entry">
<?php if(has_post_thumbnail() && get_option('theme_show_featured_image'))
      the_post_thumbnail('large', array(
     'class' => 'alignleft', 
     'style' => 'margin:0 10px 10px 0;')); ?>
<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
share|improve this question
up vote 1 down vote accepted

I assume you want this to be output inside of the_content()?

You would probably have to define a shortcode that will output the_post_thumbnail(). You could either define the shortcode to accept a URL as an argument, or else wrap the shortcode with HTML anchor tags.


Assuming you're already outputting the_post_thumbnail() inside of the_content(), you could add a custom field into which the user enters a URL, and then, if the URL is present, output anchor tags around the call to the_post_thumbnail().

share|improve this answer
Yes, Ive got it displaying fine, just need to add a custom, user-defined hyperlink option. – Scott B Apr 27 '11 at 2:43
What about using a custom field? (See answer edit.) – Chip Bennett Apr 27 '11 at 3:22

Use get_the_post_thumbnail() function for getting the featured image. This will return the img string for you, instead of echoing it immediately.

Also, add a Custom Field to the post, named, for example URL-for-featured-image, and add the URL you want the image to link to as the value. Get it's contents with get_post_custom_values('URL-for-featured-image') and use the result in the hyperlink's href.

  if(has_post_thumbnail() && get_option('theme_show_featured_image'))
    $img = get_the_post_thumbnail($post->ID, 'large'); 
    $url = get_post_custom_values('URL-for-featured-image');
    /* your code here */

share|improve this answer
thanks for the suggestion. Definitely will be adding a custom field since I now know there is no built in option to use a hyperlink for the featured image. Seems an oversight to me that its not there. Every click map I've seen tells me people click on images like mad, whether they are linked or not. – Scott B Apr 28 '11 at 17:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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