I have been looking on stack overflow and the web but can't find a simple solution for this.
I just want to add a class to the of the widget sidebar generated by Wordpress.
This is my register sidebar code:
register_sidebar( array(
'name' => __(' Main Sidebar ', 'mystic'),
'id' => 'sidebar-2',
'class' => 'submenu',
'description' => __( 'Main Sidebar', 'mystic' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h6>',
'after_title' => '</h6>'
));
The html output of the actual unordered list is:
<ul>
<li>
<a href="http://localhost:8888/a-third-post/">A Third Post</a>
</li>
<li>
<a href="http://localhost:8888/another-post/">Another Post</a>
</li>
<li>
<a href="http://localhost:8888/news-article-title/">News Article Title</a>
</li>
</ul>
But I want the ul to have a class of 'submenu'
So,
<ul class="submenu">
<li>
.....
Surely there has to be an easy way to do this?(without jQuery)
register_sidebar()
just lets you add a wrapper around widgets. So whether or not you can do this depends on the specific widget that you're using. What widget are you using here?ob_start(); dynamic_sidebar('sidebar-2'); $sidebar = ob_get_contents(); ob_end_clean(); $sidebar_corrected_ul = str_replace("<ul>", '<ul class="submenu l_tinynav1">', $sidebar); echo $sidebar_corrected_ul;
<ul>
element in any widget. But if it works, it works.