Ready to get started?Download WordPress


Widgets - Adding An Additional CSS Class (2 posts)

  1. Ryan Ball
    Posted 3 years ago #

    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>'

  2. fadingdust
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.