Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
    
1  
Please search the site for related questions before posting. This topic has been covered extensively. –  Chip Bennett Feb 4 '12 at 18:15
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.