• Greetings,

    I’m trying to customize the markup of the widgets in my sidebar for Bootstrap 3.2.0. According to Codex, “register_sidebar” should support a “class” argument:

    register_sidebar(array(
    		'name' => __('Primary Sidebar', 'bootstrapped'),
    		'id' => 'sidebar-1',
    		'description' => __('Main sidebar that appears on the left.', 'bootstrapped'),
    		'class' => 'my-class',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<div class="widget-title">',
    		'after_title' => '</div>',
    	));

    But “class” seems to be ignored (WP 3.9.2./ WP 4.0). Can anyone share a light on it’s usage?

    I know that I could solve this by css or js, but then my otherwise solid solution would get hacky.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The class parameter is passed along to the widget’s widget() method, but it is up to the widget code to do something with it. None of the default widgets seem to do this, it is apparently a parameter only useful for custom widgets.

    Your best option is to add a div with the class to the ‘before_widget’ parameter (and close it with ‘after_widget’). The only proper way to use the class parameter would be to extend the widgets you are using, modify the widget() method to make use of the class parameter, then remove the default widgets in preference for your customized versions.

    Thread Starter Demokrit

    (@demokrit)

    Hi bcworkz,

    thank you very much for the explanation. I wrote a custom navigation widget yesterday and can confirm the availability of the “class” within the custom code. But custom widgets never are a problem, since you can use any markup you like. So “class” is pretty useless unless integrated into the standard widgets. But even with a “class” feature, it would be no solid solution, since some widgets use unordered lists, others use table markup, which probably would need a different class.
    I could solve my problem by using “preg_replace” – don’t like this method, but it does it’s job for the 3-4 widgets I want to keep. The rest will be unregistered and substituted by sidebar code, which gives you much tighter control.

    Thanks again for your help,

    Thomas

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Class usage in register_sidebar’ is closed to new replies.