6 ) { // Four widgets per row if there are exactly four or more than six widgets. $widget_classes .= ' col-md-3'; } elseif ( 6 === $widget_count ) { // If exactly six widgets are published. $widget_classes .= ' col-md-2'; } elseif ( $widget_count >= 3 ) { // Three widgets per row if there's three or more widgets. $widget_classes .= ' col-md-4'; } elseif ( 2 === $widget_count ) { // If two widgets are published. $widget_classes .= ' col-md-6'; } elseif ( 1 === $widget_count ) { // If just on widget is active. $widget_classes .= ' col-md-12'; } // Replace the placeholder class 'dynamic-classes' with the classes stored in $widget_classes. $params[0]['before_widget'] = str_replace( 'dynamic-classes', $widget_classes, $params[0]['before_widget'] ); } return $params; } } // End of if function_exists( 'anzu_widget_classes' ). add_action( 'widgets_init', 'anzu_widgets_init' ); if ( ! function_exists( 'anzu_widgets_init' ) ) { /** * Initializes themes widgets. */ function anzu_widgets_init() { register_sidebar( array( 'name' => __( 'Right Sidebar', 'anzu' ), 'id' => 'right-sidebar', 'description' => __( 'Right sidebar widget area', 'anzu' ), 'before_widget' => '', 'before_title' => '