Wordpress Get The First Image


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php //GET THE FIRST IMAGE
  2. $args = array(
  3. 'order' => 'ASC',
  4. 'orderby' => 'menu_order',
  5. 'post_type' => 'attachment',
  6. 'post_parent' => $post->ID,
  7. 'post_mime_type' => 'image',
  8. 'post_sta tus' => null,
  9. );
  10. $attachments = get_posts($args);
  11. if ($attachments) {
  12.  
  13. foreach ($attachments as $attachment) {
  14.  
  15. echo wp_get_attachment_url($attachment->ID, 'full', false, false);
  16. }
  17. } ?>');">

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.