Last active
May 9, 2017 20:16
-
-
Save tiborp/96024b511858fbd74bb1 to your computer and use it in GitHub Desktop.
Dynamically add Bootstrap column classes to footer widgets, depending on how many widgets are present
This file contains hidden or 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 | |
// Dynamically add Bootstrap column classes to footer widgets, depending on how many widgets are present | |
add_filter('dynamic_sidebar_params','tibs_footer_sidebar_params'); | |
function tibs_footer_sidebar_params($params) { | |
$sidebar_id = $params[0]['id']; | |
if ( $sidebar_id == 'sidebar-footer' ) { | |
$total_widgets = wp_get_sidebars_widgets(); | |
$sidebar_widgets = count($total_widgets[$sidebar_id]); | |
$params[0]['before_widget'] = str_replace('<section class="widget ', '<section class="widget col-md-' . floor(12 / $sidebar_widgets) . ' ', $params[0]['before_widget']); | |
} | |
return $params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment