Last Updated: January 12, 2010

Wordpress 2.5 offers a great feature for adding an image gallery to posts: the gallery shortcode. There’s only one problem, how do you control exactly which images are displayed in the gallery? The answer…. “well, you can’t really”. I really wanted to be able to specify the images for each gallery, so I took some time to write the following simple plugin which adds a new parameter to the original.

As of WordPress 2.9 this plugin is no longer necessary and will no longer be developed.

Download mf_gallery_shortcode() v1.5

Installation

  1. Extract the zip file locally.
  2. Upload mf-gallery-shortcode.php to your /wp-content/plugins/ directory.
  3. Activate the plugin through the “Plugins” menu in WordPress.

Define Attachments to be Included

Insert the following code into your post’s content field specifying the attachments that you want to be displayed as a comma separated list of attachment ID’s. This parameter allows you to add only the attachments that you want displayed in each gallery. Note: attachments do not have to be children of the current page or post to be used here.

include="1,2,3,4"

Define Attachments to be Excluded

Insert the following code into your post’s content field specifying the attachments that you do not want to be displayed as a comma separated list of attachment ID’s. All attachments that are children of the current page or post will be displayed except for the ones defined in the list.

exclude="1,2,3,4"

Version info

This plugin will only work with Wordpress version 2.5. +

Notes

Version 0.1.2

  1. The attribute ‘ids’ has been depreciated. It it still supported for backward compatibility.
  2. All attachments link directly to themselves, bypassing attachment.php or any of its derivatives (image.php, pdf.php, etc…) There is no easy way to link to the attachment page while retaining the ’set’ of images defined by “include” or exclude parameters. If you have any ideas how this might be circumvented, please leave a comment below.

Version 1.4

  1. Code suggested by Gary Jones has been included in the source.

Version 1.4

  1. Replaced style tag with link tag to an external stylesheet.
  2. Stylesheet will only be enqueued when necessary.
  3. Plugin is now object-oriented.

License

GNU General Public License