0

I do not see a way to get the URL to the full sized image of an attachment.

Yes, i can use get_the_post_thumbnail_url($post->ID, 'full'), but that is of no help if the image is not the featured image.

wp_get_attachment_metadata on my attachment does not show a full size, so therefore wp_get_attachment_image_src($imageID, 'full') returns nothing.

How do I get the full version of an image given the attachment ID?

  • There is no full in sizes, the original is under the key file in the data returned from wp_get_attachment_metadata. Regardless, wp_get_attachment_image_src($imageID, 'full') is correct, and will return an array containing the URL. – Milo Jul 28 '17 at 22:35
  • I thought I tested wp_get_attachment_image_url($imageID, 'full') before posting. You are right, to my surprise. I'm not sure why I thought it was failing – Jeff Wilkerson Jul 29 '17 at 0:22
1

I think you're overthinking the system. Unfortunately the nomenclature isn't helping. The Thumbnail here is the actual image when you use get_the_post_thumbnail_url().

as an example. Say today you uploaded an image called myimage.jpg.

That would go, if you're storing images by date into this directory: /wp-content/uploads/2017/07/myimage.jpg.

Now when you call :

$featured_img_url = get_the_post_thumbnail_url('full');  //(or leave the parameter blank)

echo $featured_img_url;

you would get:

http://www.example.com/wp-content/uploads/2017/07/myimage.jpg

On the other hand if you used this code:

$featured_img_url = get_the_post_thumbnail_url('thumbnail');  //(or choose a different thumbnail size..medium...large...)

echo $featured_img_url;

it would return:

http://www.example.com/wp-content/uploads/2017/07/myimage30x30.jpg

the autogenerated image based on your thumbnail settings.

to avoid the naming confusion you could also try...

 wp_get_attachment_image_url()

but this requires the actual attachment id, not post id, whether or not you're in the loop.

$imgid = 6; //need to get it dynamically
$imgurldesktop = wp_get_attachment_image_url( $imgid, '' ); //use default image size
$imgurlmobile = wp_get_attachment_image_url( $imgid, 'home-slide-img-mobile' ); //use custom set size
  • I am talking about images uploaded via Advanced Custom Fields, and not directly tied to a post. Thats why i'm messing with wp_get_attachment_image_url(), because i know the attachment ID. – Jeff Wilkerson Jul 29 '17 at 0:25
0

I solved this using wp_get_attachment_url($imageID);

But, you can also use wp_get_attachment_image_url($imageID, 'full')

  • Jeff that's exactly what i answered you in part 2 of my answer... – rudtek Jul 29 '17 at 22:48
  • I wasn't asking about post thumbnails. I was specifically asking about attachments not directly tied to a post. feel free to adjust your answer accordingly.... and i realized I made a mistake when testing wp_get_attachment_image_url() only after @milo pointed it out. – Jeff Wilkerson Jul 30 '17 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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