'Sidebar', 'id' => 'sidebar-main', 'description' => 'Main Sidebar on the right side.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' )); } add_action( 'widgets_init', 'auenwald_theme_widgets_init' ); /** * Manages sidebar-related modifications. */ class ThemeSidebars { public function __construct() { // register footer sidebar register_sidebar(array( 'name' => 'Footer Sidebar', 'id' => 'sidebar-footer', 'description' => 'Horizontal Sidebar in the footer', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' )); // register footer widgets register_sidebar(array( 'name' => 'Footer Left', 'id' => 'footer-left', 'description' => 'Widget in the footer', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' )); // register footer widgets register_sidebar(array( 'name' => 'Footer Center', 'id' => 'footer-center', 'description' => 'Widget in the footer', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' )); // register footer widgets register_sidebar(array( 'name' => 'Footer Right', 'id' => 'footer-right', 'description' => 'Widget in the footer', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' )); // register footer widgets register_sidebar(array( 'name' => 'Footer Logo', 'id' => 'footer-logo', 'description' => 'Widget Logo in footer', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' )); // Add filter for the footer-sidebar // Only apply this filter, if not the admin-panel is requested if (!is_admin()) { add_filter('dynamic_sidebar_params', array($this, 'dynamicFooterParams')); } } /** * Filters the params for the sidebars * * @param array $params The params of the widget * * @return array The params of the widget */ public function dynamicFooterParams($params) { // only affect the params of the sidebar-footer if ($params[0]['id'] == 'sidebar-footer') { // Add a uk-width-medium-1-x class, where x is the number of the widgets within the sidebar $class = 'uk-width-medium-1-' . $this->getWidgetsCount('sidebar-footer'); $params[0]['before_widget'] = preg_replace('(class=")', 'class="' . $class . ' ', $params[0]['before_widget']); } return $params; } /** * Return the number of widgets within a sidebar */ private function getWidgetsCount($sidebar_id) { $sidebars_widgets = wp_get_sidebars_widgets(); return (int)count((array)$sidebars_widgets[$sidebar_id]); } }