Advertisement
miriamdepaula

WordPress: Bootstrap 4 Gallery (Filter default gallery)

Jul 28th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. /**
  2.  *  Bootstrap 4 gallery
  3.  *  Base galeria padrão / Default gallery: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/media.php#L1677
  4. */
  5. add_filter( 'post_gallery', 'wpmidia_bootstrap_gallery', 10, 2);
  6. function wpmidia_bootstrap_gallery( $output = '', $atts ) {
  7.  
  8.     if (strlen($atts['columns']) < 1) $columns = 3;
  9.     else $columns = $atts['columns'];
  10.     $images = explode(',', $atts['ids']);    
  11.    
  12.     if ( $columns < 1 || $columns > 12 ) $columns == 3;
  13.    
  14.     $col_class = 'col-lg-' . 12/$columns;
  15.    
  16.     $output = '<div class="row text-center text-lg-left gallery">';
  17.     $i = 0;
  18.    
  19.     foreach ( $images as $key => $value ) {
  20.        
  21.         $image_attributes = wp_get_attachment_image_src( $value, 'full'); //"Full" para o responsivo :)
  22.         $output .= '
  23.            <div class="'.$col_class.'">
  24.              <a data-gallery="gallery" href="'.esc_url($image_attributes[0]).'" class="d-block mb-4 h-100">
  25.                    <img src="'.esc_url($image_attributes[0]).'" alt="" class="img-fluid img-thumbnail">
  26.                </a>
  27.            </div>';
  28.         $i++;
  29.     }
  30.    
  31.     $output .= '</div>';
  32.    
  33.     return $output;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement