Title: Cleaner Bootstrap Gallery Shortcode
Last modified: August 24, 2016

---

# Cleaner Bootstrap Gallery Shortcode

 *  [amrinz](https://wordpress.org/support/users/amrinz/)
 * (@amrinz)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/cleaner-bootstrap-gallery-shortcode/)
 * Hi,
 * I create my own gallery shortcode using bootstrap 3 layout.
    I want to share 
   it, but also need more cleaner way since I just modify some code I found to create
   this shortcode.
 * The code consist of 3 functions:
 *     ```
       /* Bootstap Gallery
        * Usage:
        * [btgalleryStart class='for first row only - leave empty for else']
        *		[btgallery-item col="4" src="image url" alt=""]
        *		[btgallery-item col="4" src="image url" alt=""]
        *		[btgallery-item col="4" src="image url" alt=""]
        * [btgalleryEnd]
        */
       function lmd_btGalleryTop($atts, $content = null) {
          extract(shortcode_atts(array(
           'bg_class' => 'btgallery'
          ), $atts));
          return '<div class="row btgallery '.$bg_class.'">';
       }
       add_shortcode("btgalleryStart", "lmd_btGalleryTop");
   
       function lmd_btGalleryBottom() {
          return '</div>';
       }
       add_shortcode("btgalleryEnd", "lmd_btGalleryBottom");
   
       function lmd_btGalleryItem($atts, $content = null) {
          extract(shortcode_atts(array(
           'col' => 4,
       	'src' => '',
       	'alt' => ''
          ), $atts));
          return '<div class="col-md-'.$col.'"><img src="'.$src.'" class="img-responsive" /></div>';
       }
       add_shortcode("btgalleryItem", "lmd_btGalleryItem");
       ```
   
 * and the usage:
 *     ```
       [btgalleryStart]
       [btgalleryItem src="https://amrinz.files.wordpress.com/2015/04/gili-trawangan-island.jpg" col=4 alt="just example"]
       [btgalleryItem src="https://amrinz.files.wordpres.com/2015/04/gili-trawangan-island.jpg" col=4 alt="just example"]
       [btgalleryItem src="https://amrinz.files.wordpress.com/2015/04/gili-trawangan-island.jpg" col=4 alt="just example"]
       [btgalleryEnd]
       ```
   
 * Its working but I think there is another way to join those functions and make
   it more efficient. Help me to make it look like this:
 *     ```
       [btgallery class="myClass" col=2]
         [btgalleryItem src="" alt=""]
         [btgalleryItem src="" alt=""]
       [/btgallery]
       ```
   
 * Thanks for your help

The topic ‘Cleaner Bootstrap Gallery Shortcode’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [amrinz](https://wordpress.org/support/users/amrinz/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/cleaner-bootstrap-gallery-shortcode/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
