Created
March 7, 2018 22:00
-
-
Save infn8/c97aa2809d6600c91b0a8c05bbb27060 to your computer and use it in GitHub Desktop.
Show Bootstrap Sizers in Wordpress
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 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