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'm buiding a site that lists the most recent posts on the front page, the site is a recompilation of interesting articles and images so it doesn't make sense to link to the individual post.

I currently have the title redirecting externally to the link, but I would also like to link externally via the post image.

I've set up a custum field "externalurl"

This is what I have so far in the loop.php which does not work:

    if ( has_post_thumbnail() ){ ?>
        <?php $thumbURL = get_post_custom_values('externalurl'); ?>
        <a href="<?php echo get_attachment_link($thumbURL); ?>" rel="gallery" title="<?php the_title(); ?>">        
            <?php the_post_thumbnail(); ?>
            <span class="view-large"></span>
    <?php } ?>

Does anybody have any idea what I'm doing wrong? Any suggestions welcome.

Thanks in advance!

share|improve this question


wouldn't echoing get_post+meta in the a link be best?

<a href="<?php echo get_post_meta($post->ID, "externalurl", true) ); ?>" rel=...and so on
share|improve this answer
Also: be sure to wrap that in esc_url(), e.g. <?php echo esc_url( get_post_meta( $post->ID, 'externalurl', true) ); – Chip Bennett Aug 12 '11 at 18:26
Something I hadn't learned about back in March, thank you!! – Rev. Voodoo Aug 14 '11 at 10:53

Your Answer


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