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

share|improve this question
up vote 2 down vote accepted

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)
share|improve this answer
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 '12 at 3:51

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.