Created
December 30, 2016 09:56
-
-
Save najlepsiwebdesigner/70096d99cf0014b3860f46f56e7b82b6 to your computer and use it in GitHub Desktop.
make wordpress gallery responsive with bootstrap grid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function bootstrap_gallery( $output = '', $atts, $instance ) | |
{ | |
if (strlen($atts['columns']) < 1) { | |
$columns = 3; | |
} | |
else { | |
$columns = $atts['columns']; | |
} | |
$images = explode(',', $atts['ids']); | |
if ($columns < 1 || $columns > 12) { | |
$columns == 3; | |
} | |
$col_class = 'col-xs-' . 12/$columns; | |
$return = '<div class="row gallery">'; | |
$i = 0; | |
foreach ($images as $key => $value) { | |
if ($i%$columns == 0 && $i > 0) { | |
$return .= '</div><div class="row gallery">'; | |
} | |
$image_attributes = wp_get_attachment_image_src($value, 'full'); | |
$return .= ' | |
<div class="'.$col_class.'"> | |
<div class="gallery-image-wrap"> | |
<a data-gallery="gallery" href="'.$image_attributes[0].'"> | |
<img src="'.$image_attributes[0].'" alt="" class="img-responsive"> | |
</a> | |
</div> | |
</div>'; | |
$i++; | |
} | |
$return .= '</div>'; | |
return $return; | |
} | |
add_filter( 'post_gallery', 'bootstrap_gallery', 10, 4); | |
?> |
XNicON
commented
Oct 1, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment