# Custom gallery format (using Bootstrap v3 grid) * Original function by: [bitWorking](https://stackoverflow.com/users/1948627/bitworking) * Modified by: [TMMC](https://stackoverflow.com/users/2103923/tmmc) * StackOverflow question URL: https://stackoverflow.com/a/35776752 ## Usage 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); ``` ## Fixed/added 'missing' features 1. 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. 2. Generating thumbnail `alt` attribute set by user via WordPress gallery panel. 3. 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. ## Minor changes * Renamed function `bootstrap_gallery` to `custom_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` from `foreach` loop. * Changed the name of `$value` variable to `$imageID` in `foreach` loop. * Added wrapper `section.gallery` around all `div.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` to `switch` 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` to `figure`. * Changed size of displayed file to `large` insted of `full`. * Added ability to give thumbnail link more attributes. * Added comments. ## TODO * 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?