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

How do I get the URL of only the first picture in a Wordpress post? I don't want the URL of the thumbnail, but the first picture in the post loop. I only need the URL for linking purposes.

Thanks for your help everyone!

share|improve this question
Please search the site for related questions before posting. This topic has been covered extensively. – Chip Bennett Feb 4 '12 at 18:15
up vote 0 down vote accepted

The answer is in Codex.

Note that wp_get_attachment_image_src returns the URL of an image's full version if you want.

share|improve this answer
Thanks Raphael. But if I were to use the function within the loop, how do I make it takes only the first image in a post on a post page? Would the $attachment_id be 1 or 0? – Karl Feb 8 '12 at 4:18
Nvm! I used get_post_thumbnail_id() to use as the $attachment_id in the function. Worked great! Thanks Raphael. – Karl Feb 8 '12 at 5:19

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.