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

I'm having trouble removing the featured image from gallery.

enter image description here

I removed all kinds of stuff from those 2 files, but seems like I need to add something, not take away. Here are the pastebin's of 2 files:



share|improve this question
I think this question has been answered here: stackoverflow.com/questions/4337999/… – Matt.C Aug 5 '13 at 16:15
I've tried those. I included them in multiple places, but failed :S But thanks for reference! And thanks to s_ha_dum for converting link to image, nice! – Joonas Luik Aug 5 '13 at 16:24
Another approach would be using the shortcode_atts_gallery filter introduced in WP 3.6. It allows to change all attributes – and therefore the passed IDs – without much hassle. See: markjaquith.wordpress.com/2013/04/04/… and github.com/WordPress/WordPress/blob/master/wp-includes/… – swissspidy Aug 6 '13 at 9:17
Sorry, but I don't quite understand how it would work. There's no [gallery] shortcode used in the theme I use. – Joonas Luik Aug 6 '13 at 9:30
up vote 0 down vote accepted

Assuming that you are using the standard functionality of the gallery:

[gallery ids = "1,2,3,4,5,6,7,8"]

You can extract the id of the images without having to do a query for attachments of that post with:

preg_match('/\[gallery.*ids=.(.*).\]/', get_the_content(), $ids);

Then make an array of these values:

$ids = explode( ',' $ids[1] );

Eventually check if the id of the featured image exists and get its position( i think that it doesn't exists till you don't place it inside the gallery ):

$pos = array_search( get_post_thumbnail_id( get_the_ID ), $ids);

unset that value:


now you have all the attachments ids, less the one of featured image stored in $ids array.



    $query_images_args = array(

       'post_type' => 'attachment',
       'post_mime_type' =>'image',
       'post_status' => 'inherit',
       'posts_per_page' => -1,
       'post_parent' => get_the_ID(),
       'exclude' => get_post_thumbnail_id(),
       'orderby' => 'menu_order',
       'order' => 'ASC',


    $images = get_posts( $query_images_args );


    <div class="sidebar-item not-in-responsive">

        <script type="text/javascript">

            jQuery(document).ready(function() {




    <ul id="property-gallery-thumbs">


        $i = 1;     
        if( $images ) : foreach( $images as $image ) : setup_postdata( $image ); ++$i;


            <li class="thumb<?php if($i==1) { echo ' current'; } ?><?php if($i%3 == 0) { echo ' last'; } ?>">

                <span class="hidden full"><?php echo wp_get_attachment_url( $image->ID ); ?></span>
                <span class="hidden main"><?php echo ddTimthumb(wp_get_attachment_url( $image->ID ), 680, 450); ?></span>
                <span class="thumb"><img src="<?php echo ddTimthumb(wp_get_attachment_url( $image->ID ), 76, 76); ?>" alt="<?php the_title() ?>" title="<?php the_title(); ?>" /></span>


        <?php endforeach; wp_reset_postdata(); ?>

    <!-- /#property-gallery-thumbs/ -->


    <?php endif; ?>
share|improve this answer
Thanks for comment! Sadly, this didn't work :/ – Joonas Luik Aug 5 '13 at 16:35
sorry, i'm updating the answer. i hope new solution works – iEmanuele Aug 5 '13 at 16:37
Sorry for wasting your time mang, didn't manage to get it to work, got : Parse error: syntax error, unexpected 'ids' (T_STRING), expecting ']' in / error. But there's [gallery] nowhere in my theme's code, so I'm not sure if the whole thing you just wasted so much time on applies. Sorry again, upvoted your comment. – Joonas Luik Aug 5 '13 at 17:30
can you update your gallery template paste on pastebin or make a new one? – iEmanuele Aug 5 '13 at 17:48
This last update returns in: Fatal error: Call to undefined function wp_resetpostdata() on line 51. Error goes away when I remove wp_resetpostdata. It now hides the thumbnail, but the big image is still there. – Joonas Luik Aug 5 '13 at 22:13

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.