0

I have created a sidebar:

function my_sidebar() {

    register_sidebar(
        array(
            'name'          => 'Blog Sidebar',
            'id'            => 'blog-sidebar',
            'description'   => 'Sidebar For Blog Page',
            'before_widget' => '<div class="widget">',
            'after_widget'  => '</div>',
            'before_title'  => '<h5 class="widget-title">',
            'after_title'   => '</h5>'
        )
    );
}

add_action( 'widgets_init', 'my_sidebar');

I just added the "recent posts" widget and want to add a class to the <ul> tag but I can't seem to figure out how to do it in a simple way. I just want the <ul> tag to change to <ul class="link-list">

1

The quickest and practical solution for you would be to add your custom class to the before_widget wrapper:

'before_widget' => '<div class="widget ul-link-list">'

Then use CSS rules accordingly:

.ul-link-list ul {
  /* Some CSS rules */
}
  • Thanks for your comment but that results in <div class="widget ul-link-list"> which is not what I want. I want to add a class to my ul list, not the div with class of 'widget'. – user8463989 May 6 '18 at 11:30
  • 1
    As i stated, this is the quickest workaround for you. Otherwhise you'll have to use javascript to dynamically add the CSS class to your ul element, or use some other wp hooks along with ob_start() and ob_get_clean() functions (you will probably also need regexp for this) – Eduardo Escobar May 6 '18 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.