Skip to content

Instantly share code, notes, and snippets.

@infn8
Created March 7, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infn8/c97aa2809d6600c91b0a8c05bbb27060 to your computer and use it in GitHub Desktop.
Save infn8/c97aa2809d6600c91b0a8c05bbb27060 to your computer and use it in GitHub Desktop.
Show Bootstrap Sizers in Wordpress
<?php
function getBootstrapBreakpoints() {
return array(
'xs',
'sm',
'md',
'lg',
'xl',
);
}
function get_display_classes($showSizes, $show = 'block', $hide = 'none'){
$classes = [];
foreach ($showSizes as $breakpoint => $display) {
if ($display) {
$classes[] = "d-$breakpoint-$show";
} else {
if ($breakpoint === 'xs') {
$classes[] = "d-$hide";
} else {
$classes[] = "d-$breakpoint-$hide";
}
}
}
return implode(' ', $classes);
}
function showSizers() {
if (!empty($_REQUEST['showSizers'])) {
echo '<div class="fixed-bottom show-sizers">';
$sizes = getBootstrapBreakpoints();
$allOff = [];
foreach ($sizes as $size) {
$allOff[$size] = false;
}
foreach ($sizes as $size) {
$theseBreaks = $allOff;
$theseBreaks[$size] = true;
$classes = get_display_classes($theseBreaks, 'inline-block');
echo "<div class=\"$classes btn btn-info btn-lg sizer\">$size</div>";
}
echo '</div>';
}
}
add_action( 'wp_footer', 'showSizers' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment