I'm trying to get the link to the thumbnail size of an attachment image.

I tried this:

wp_get_attachment_link( $img_id, 'thumbnail' );

but it returns the actual HTML for the image wrapped in a link. I want just the bare URL directly to that size image.

Does Wordpress have a different function I should be using, or do I have to extract it from the HTML returned by wp_get_attachment_link?

1 Answer 1


What about using wp_get_attachment_image_src?

Using wp_get_attachment_image_src:

$src = wp_get_attachment_image_src( $img_id, 'thumbnail' );
$src = $src[0]; // Grabs only the URL ($src[1] = width of image, $src[2] = height of image)
  • Thanks. That's exactly what I needed. I swear I searched through the Codex before asking here. Somehow I feel that the Codex is not properly (read: messy) organized.
    – MegaHit
    Jan 30, 2012 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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