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 have this function:

function get_image_link( &$post ) {
         $image_link_meta = get_post_meta( $post->ID, 'as_link_to_image', true ); 

         $image_link_from_post = '';

         if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $post->ID ) ) {
            $attachment_image_link = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), full );

         if ( $attachment_image_link[0] )
            $image_link_from_post = $attachment_image_link[0];

         if( !empty( $image_link_meta ) ) 
            $final_image_link = $image_link_meta;

         elseif( !empty( $image_link_from_post ) )
            $final_image_link = $image_link_from_post; 

            $final_image_link = WP_PLUGIN_URL . '/link/to/no-image.png';

         return $final_image_link;

Any idea why $image_link_from_post isn't getting a value?

share|improve this question
Cannot reproduce. Aside from missing quotes around full and extra bracket at the end this seems to be working. – Rarst Feb 1 '11 at 6:41
up vote 1 down vote accepted

This should be able to return the url of the large image.

$largeImg = wp_get_attachment_link( $attachment_id, 'large', false );

There's also this incase that doesn't work.

wp_get_attachment_image_src( $attachment_id, 'large' );
share|improve this answer

Great Snippet available here from the guys at CSS-Tricks:

$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];

When I first tried this solution it kept throwing 'Missing Attachment' because I was referencing the post ID instead of the attachment ID. Anywho this little snippet helped clear that up for me. First comment reduces it to one line!


share|improve this answer

This line right here:

if ( !$attachment_image_link[0] )
            $image_link_from_post = $attachment_image_link[0];

You're only assigning the $image_link_from_post variable to the post thumbnail if the post thumbnail does not exist. Take out the NOT operator in the conditional and it should work more the way you intend.

Update: oops, weird, I just copied that line out of your code, but now its not there. Did you already solve the problem?

share|improve this answer
corrected it.. it was a typo :-) – Joann Feb 1 '11 at 0:01
Does the function work now for you? – goldenapples Feb 1 '11 at 0:01
No, unfortunately.. – Joann Feb 1 '11 at 0:05
In that case I'm not sure. You should quote 'full' in the call to get_post_thumbnail_id. Also, check for current_theme_supports( 'post-thumbnails' ) rather than function_exists( 'has_post_thumbnail' ), that's all I can offer. – goldenapples Feb 1 '11 at 0:17
I added support to my theme already particularly in functions.php. Thanks for the time! – Joann Feb 1 '11 at 0:22

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.