Get the url of the full sized attachment image using post ID?

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; 

         else
            $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?

Related posts

Leave a Reply

3 comments

  1. 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' );
    
  2. 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!

    Cheers!

  3. 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?