- Original function by: bitWorking
- Modified by: TMMC
- 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
altattribute 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
idfor each gallery block based on$instance.
- Renamed function
bootstrap_gallerytocustom_gallery_gridso anyone can adapt it to any other framework without the name beeing misleading. - Changed the name of
$attsparameter to$attrs. - Removed redutant
$keyfromforeachloop. - Changed the name of
$valuevariable to$imageIDinforeachloop. - Added wrapper
section.galleryaround alldiv.rows and removed.galleryclass from each.rows. - Changed default column class from
.col-md-Xto.col-sm-X. - Added function
custom_gallery_itemfor generating single gallery item. - Changed
if-elsetoswitchfor columns + added 4 and 6 columns layout (5, 7, 8 and 9 fall back to 3). - Changed name of the variable
$returnto$gallery. - Changed single item from
divtofigure. - Changed size of displayed file to
largeinsted offull. - Added ability to give thumbnail link more attributes.
- Added comments.
- Thumbnail captions with
figcaption. - Gallery layout for 5, 7, 8 and 9 columns (maybe with
.col-sm-offset-X?). - Title attribute for gallery links maybe?