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.

Is there a way to prevent the featured image from even showing up in a post's gallery?

e.g. when editing the gallery in the admin for a post, the featured image isn't there.

share|improve this question
    
Sorry, but what do you mean by that? Are you talking about the title? –  All4Gaming Sep 17 '12 at 23:59
    
Ah, my failure. I had several tabs open and was reviewing questions. Seems like I mixed up the questions and added the comment to the wrong question. –  kaiser Sep 18 '12 at 0:11
    
Haha that's okay! –  All4Gaming Sep 18 '12 at 0:15
add comment

3 Answers 3

I am agree with @janw's answer.

I would like to add further as:

You can edit your single template to automatically show the gallery without needing to insert the gallery shortcode manually. Open your single.php file and inside the loop, where you want the gallery to be displayed, copy this line of code:

<?php  $id = get_post_thumbnail_id(get_the_ID()); // gets the post thumbnail ID ?>
<?php echo do_shortcode("[gallery exclude={$id}]"); // insert the gallery without the thumbnail ?>
share|improve this answer
add comment

Okay, I had the same problem and just solved it by adding an "exclude" field to the shortcode. Like so...

[gallery link="file" columns="4" orderby="title" exclude="1050"]

You have to just pull the ID number of the file you don't want to show. This works without adding any functions or edits to the theme.

share|improve this answer
add comment

If you use the gallery shortcode you can add the exclude param with the id of the featured image to exclude it.

If you want to do it dynamically I suggest using the post_gallery filter.

<?php // add to functions.php
add_filter ('post_galley', 'exclude_featured_img');
function exclude_featured_img($attr)
{
    if (!isset($attr['exclude']) || empty($attr['exclude'])) {
        return $attr['exclude'] = get_post_thumbnail_id();
    } else {
        return $attr['exclude'] = $attr['exclude'] . ',' . get_post_thumbnail_id();
    }
}

not tested but should work.

share|improve this answer
    
I am trying to do this same thing and the code did not work. The featured image is still sitting in the middle of the gallery. –  Liana Mir Nov 8 '12 at 1:37
    
Actually this will not work, as the post_galley is intended to filter the entire output of the [gallery] shortcode, not the $atts passed. So if you return '<div>' in exclude_featured_img function for example, the [gallery] shortcode will print <div> on the screen. In order to use this filter correctly, you have to re-write the entire output of the gallery shortcode while specifying the exclude argument. See this answer for more details. –  Ahmad M Nov 8 '12 at 2:36
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.