Skip to content

How To Exclude An Image From Your WordPress Gallery

by Scott on March 27th, 2011
wp-gallery-image-excluded

If you’ve ever added the Gallery to one of your WordPress Posts, you might have had the frustration of keeping the other images in that same Post from appearing in the Gallery. This can come up if your WordPress theme supports Featured Images. It can also come up when you want to include other images in your Post but want to exclude those from the Gallery.

First of all, the fix isn’t about installing a plugin. At least I didn’t find a plugin that handled this without radically changing the nature of the Gallery. The solution is a tiny bit of code I found out about at WordPress support. (I was surprised that the forums were not very good at answering this question.)

Here is what you need to do:

With the Gallery already added to your post, go into your Post Editor. You want to edit the post containing the Gallery.

Click the tab to view the post in HTML.

Scroll to the area where you see the code for the gallery. If you’re not used to reading HTML, get over it. It’s not real code. Think of HTML as a dumb word processor. It’s so dumb you have to code how to <bold>bold</bold> a word. Now scroll down the HTML and find the tag:

[gallery]

This is where you’re going to add a your exclude code. (cough) I mean HTML tag.

Now, before you can do this, you need to know what the ID# is for the image you want to exclude. To find this out, just Preview your article. Then click on the image in the Gallery that you want to exclude. Look up in your browser’s URL location bar you’ll see the URL for that image. The end of the URL shows the ID#. Copy that number.

Return to your Editor and HTML.

The syntax for excluding an image from your Gallery is:

[gallery exclude="your ID #"]

*If you want to exclude more than one number use commas to separate like this (shown with sample numbers):

[gallery exclude="24,30,43"]

Here is what the finished code for excluding one image from the Gallery looks like :

[gallery exclude="1134"]

In the above case the image with the ID# of 1134 was excluded from the Gallery on my article about making paper boats. That was the image I only wanted to use as the Featured Image. Notice that image is NOT in the Gallery.

From → Advice, Wordpress

Facebook comments:

  • http://marklaudenbach.com Mark Laudenbach

    Thank you for this.

    I’ve been trying to figure out how to do this for a few years now.

    Mark

  • Steve Parker

    Or, an even easier solution. Upload your “featured images” via the Media tab instead of in the post. That way, they won’t be linked to the post. Then in your post, use the “Featured Image” chooser and choose them from the media library rather than the gallery.

    I’ve added “featured” to all my featured image names to make them easier to find.

    Steve

  • Scott

    Interesting Steve, I’ll have to give that a shot. Thanks for stopping by…