WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 have a thumbnail of the featured image, which is linked to a larger version of the file. At the moment the file just opens in a standard browser window, but I would like it to open in an attachment page, but I can't figure out how to do it! Here is what I have at the moment:

<?php if ( has_post_thumbnail()) : ?>
<div class="spudpictureandcontentwrapper">
<div class="illustration">
<?php  $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
the_post_thumbnail('thumbnail'); ?>

<?php endif; ?>

I'm guessing I need to use a different function to pass a value to $large_image_url but can't work out which one.

share|improve this question
well i guess you want to load that image in another tab it seems, if thats the case you can use target="_blank" attribute of anchor tag <a target="_blank" href="..... </a> – pr1nc3 Aug 23 '13 at 12:24
No, I'd want it in the same browser window so that the 'back' button is still available, the users will be quite old and I don't want to confuse them by taking them to a new window – Mactonex Aug 23 '13 at 12:26
At the moment the file just opens in a standard browser window, but I would like it to open in an attachment page<-- i dint get it. could you show me the link ? – pr1nc3 Aug 23 '13 at 12:28
yes i see upon clicking image gets loaded in the same window.what you mean by "attachment page" ? do you want to open this image in thick box ? google thick box if you dont know about it . – pr1nc3 Aug 23 '13 at 12:44

Use get_attachment_link to get a link to the attachment page or take a look at wp_get_attachment_link which might simplify the process.

<?php if(has_post_thumbnail()) : ?>
    <div class="spudpictureandcontentwrapper">
    <div class="illustration"><?php

        $attachment_id = get_post_thumbnail_id();

        $large_image_url = wp_get_attachment_image_src($attachment_id, 'large');

        $attachment_page = get_attachment_link($attachment_id);

        echo '<a href="' . esc_url($attachment_page) . '" title="' . esc_attr(get_the_title($attachment_id)) . '" >';

        the_post_thumbnail('thumbnail'); ?>


<?php endif; ?>
share|improve this answer

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.