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">
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">
2 Answers
Reset to default 1The 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 */
}
It's not possible to modify markup normally via actions/filters because markup is hardcoded in Wordpress \wp-includes\theme-compat\sidebar.php
So it's possible to change only via js, or php html output parsing