I am looking for this answer everywhere and can't find it. I setuo the wordpress default gallery using the attachment page which shows next and previous photos. everything is working fine and I have a loop of gallery with next and previous image post.

now, inside the gallery page where I uploaded all the photos I also added a "featured image" for a reason that I am using. unfortunately, it added this photo to my gallery loop as the last photo. I would like to exlclude the "Featured Image" from showing anywhere in the gallery (I use it only for a certain purpose)

I was looking at the code in the attachment.php and found this line which represents the photos:

<a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
                            $attachment_size = apply_filters( 'twentyten_attachment_size', 900 );
                            echo wp_get_attachment_image( $post->ID, array( $attachment_size, 9999 ) ); // filterable image width with, essentially, no limit for image height.

I have no idea how to exclude it. can anyone help? any maybe function that does it? Thanks a lot


  • We need to see the code that is actually outputting the gallery. May 23, 2012 at 19:02
  • mrwweb - I am using the [gallery] shortcode but what I am talking about is not in the gallery template. it's inside a photo post after clicking on a picture in the gallery. also, please let me know how do I increase my rate. Thanks a lot
    – gil hamer
    May 24, 2012 at 5:51
  • Chip Bennett - I just put this small portion of the code that actually creates the photos loop. the entire code can be found inside attachment.php here is a link to the file: dl.dropbox.com/u/4405634/attachment.php Thanks a lot
    – gil hamer
    May 24, 2012 at 5:52

1 Answer 1


So finally I managed to sort of fix it myself and wanted to share it if anyone finds it helpful. not the best solution in the world but still.. just uploaded the image via the Media section and not from within the post/page and then used it in the post as a featured image which wasn't uploaded directly from there, therefore, it wasn't included in the gallery pictures loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.