Add class to WordPress sidebar navigation lists

I’m just wondering if there’s a way to add a class to any navigation lists for things like sub-pages, categories, archives, meta?

I can’t find anywhere in my templates to add a class as I guess it’s all autogenerated?

My parent theme (html5blank) has a section of code (below) where this is referenced but I think it targets all lists in the sidebar…

if (function_exists('register_sidebar'))
{
    // Define Sidebar Widget Area 1
    register_sidebar(array(
        'name' => __('Widget Area 1', 'html5blank'),
        'description' => __('Description for this widget-area...', 'html5blank'),
        'id' => 'widget-area-1',
        'before_widget' => '<div id="%1$s" class="%2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    ));

    // Define Sidebar Widget Area 2
    register_sidebar(array(
        'name' => __('Widget Area 2', 'html5blank'),
        'description' => __('Description for this widget-area...', 'html5blank'),
        'id' => 'widget-area-2',
        'before_widget' => '<div id="%1$s" class="%2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    ));
}

I realised I can add a class to a parent div by amending the before_widget line to read something like:

'before_widget' => '<div id="%1$s" class="%2$s CUSTOM-CLASS-HERE">',

That does add a class but I still thing it’ll be added to any and every widget that’s added to the sidebar?

Presumably that will mean any widget that contains a ul will inherit styles applied to that class, which will break the widget’s appearance?

Hope someone can help with this 🙂

Read more here: Add class to WordPress sidebar navigation lists

Leave a Reply

Your email address will not be published. Required fields are marked *