Skip to content

Instantly share code, notes, and snippets.

@tiborp
Last active May 9, 2017 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tiborp/96024b511858fbd74bb1 to your computer and use it in GitHub Desktop.
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
<?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