Wordpress Excluding Featured Image from Gallery


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

This snippet will exclude the featured image from the attached images (gallery)


Copy this code and paste it in your HTML
  1. <?php
  2. $thumb_ID = get_post_thumbnail_id( $post->ID );
  3. if ( $images = get_children(array(
  4. 'post_parent' => get_the_ID(),
  5. 'post_type' => 'attachment',
  6. 'post_mime_type' => 'image',
  7. 'exclude' => $thumb_ID,
  8. ))) : ?>
  9. <ul>
  10. <?php foreach( $images as $image ) : ?>
  11. <li><?php echo wp_get_attachment_link($image->ID, 'thumbnail-latest'); ?></li>
  12. <?php endforeach; ?>
  13. </ul>
  14. <?php else: // No images ?>
  15. <!-- This post has no attached images -->
  16. <?php endif; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.