Support » Plugins » Widgets – Adding An Additional CSS Class

  • scarekrow76


    Is there any way to add an additonal CSS class to the widget markup?

    I’ve registered a new sidebar via the following snippet and I’d like to insert an additional CSS class: “widget-x” (x being the order/position of the widget within the sidebar). Any suggestions?

    ‘id’ => ‘footer’,
    ‘name’ => __(‘Footer’),
    ‘description’ => __(‘Widgets in this area will be shown witin the footer.’),
    ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h2>’,
    ‘after_title’ => ‘</h2>’

Viewing 1 replies (of 1 total)
  • fadingdust


    Here ya go:

    function widget_index_class($params){
    $params[0][‘before_widget’] = preg_replace( ‘/class=”/’, “class=\”widget-index{$this_widget_index} “, $params[0][‘before_widget’], 1 );
    return $params;
    add_filter(‘dynamic_sidebar_params’, ‘widget_index_class’);

    Add the above to functions.php.. I’ve got it after the sidebars are registered.

Viewing 1 replies (of 1 total)
  • The topic ‘Widgets – Adding An Additional CSS Class’ is closed to new replies.