With GIC, you can display the title, caption, and description image attributes. You can also change/filter the rendering HTML to whatever you want.
After installing and activating GIC, write your filter and add the WordPress Gallery shortcode to your page.
If you’ve been dreaming of writing a filter to customise the gallery image captions, then this plugin is for you.
Motivation
The default WordPress gallery shortcode will only display the caption from the media’s attachment metadata. Sometimes it’s nice to display more like the title—even the description.
The GIC plugin overrides the WordPress gallery shortcode function to create a hook. With this hook you can do a little bit more than just displaying the caption.
Some premium themes hide the caption completely. This leaves photography lovers like me scratching their head and spending precious time cobbling together makeshift caption blocks.
Usage
Custom Filter For Displaying Captions
The crux of this plugin is the ability to filter the gallery image caption. The galimgcaps_gallery_image_caption hook makes this possible.
For the usage examples below, this is the filter used.
Feel free to use this filter code as a starter template. After activating the GIC plugin, add the code above to your child theme’s functions.php file. Rename the function and tweak the return string to suit your needs.
New Filter To Get Custom Fields
To use these two custom fields, your galimgcaps_gallery_image_caption would look something like this.
Since v1.2.0, GIC automatically adds an Image ID column to your WordPress Media Library. This is to help you add the image IDs to your GIC shortcodes.
See where GIC automatically adds an Image ID column to your WordPress Media Library.
New in v1.4.0, GIC support custom media attachment fields.
Usage Example 1
Shortcode
For starters, let’s use a
tag for the caption tag.
Styling
Let’s override the generated styles with our own style for one particular image.
Usage Example 2
Shortcode
A 2 column x 1 row gallery with large size images using an H4 for the caption.
A 3 column x 1 row gallery with medium size images using a blockquote for the caption.
Did you notice that we are using
in the second shortcode? Let’s give it try just for kicks.
Styling
Responsive CSS Example
I recommend adding the following media queries if you use galleries with more than one image. The two media queries below will stack 2×1 and 3×1 galleries into a 1 column x n rows or 2 column x n rows as needed.

评论0