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.

  • Sorry, but what do you mean by that? Are you talking about the title?
    – All4Gaming
    Commented Sep 17, 2012 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
    Commented Sep 18, 2012 at 0:11
  • Haha that's okay!
    – All4Gaming
    Commented Sep 18, 2012 at 0:15

3 Answers 3


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.


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 ?>

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.

  • 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
    Commented Nov 8, 2012 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
    Commented Nov 8, 2012 at 2:36

Your Answer

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

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