- Original function by: bitWorking
- Modified by: TMMC
- Further modified by Shansmith01
- StackOverflow question URL: https://stackoverflow.com/a/35776752
Place the custom-gallery-markup.php
file wherever you like in your theme directory.
For sake of this example it is inc
directory.
In your functions.php
file add those lines:
require_once('inc/custom-gallery-format.php'); // change the path to match the location if needed
add_filter('post_gallery', 'custom_gallery_grid', 10, 3);
- Generating thumbnail size set by user via WordPress gallery panel.
- Using full size image was waste of bandwidth.
- If original images were not same size gallery might appear not fine.
- The CMS user might be confused if he/she set specific thumbnail size and gallery would show different size/proportions.
- Generating thumbnail
alt
attribute set by user via WordPress gallery panel. - Make thumbnails linking (set via WordPress gallery panel) work correctly (none, attachment page, file) to maintain functionality of the panel and not to confuse the CMS user.
- Generating
id
for each gallery block based on$instance
.
- change img-responsive to img-fluid
- Thumbnail captions with
figcaption
.
- Renamed function
bootstrap_gallery
tocustom_gallery_grid
so anyone can adapt it to any other framework without the name beeing misleading. - Changed the name of
$atts
parameter to$attrs
. - Removed redutant
$key
fromforeach
loop. - Changed the name of
$value
variable to$imageID
inforeach
loop. - Added wrapper
section.gallery
around alldiv.row
s and removed.gallery
class from each.row
s. - Changed default column class from
.col-md-X
to.col-sm-X
. - Added function
custom_gallery_item
for generating single gallery item. - Changed
if-else
toswitch
for columns + added 4 and 6 columns layout (5, 7, 8 and 9 fall back to 3). - Changed name of the variable
$return
to$gallery
. - Changed single item from
div
tofigure
. - Changed size of displayed file to
large
insted offull
. - Added ability to give thumbnail link more attributes.
- Added comments.
- Gallery layout for 5, 7, 8 and 9 columns (maybe with
.col-sm-offset-X
?). - Title attribute for gallery links maybe?
This is awesome, thank you very much Shannon.