I have two sidebars using the register_sidebars
function that display each widget as a list item with a class of .box
:
<?php if(function_exists('register_sidebars')){
register_sidebars(2, array(
'name'=>'sidebar%d',
'id' =>'sidebar',
'before_widget'=>'<li class="box">',
'after_widget'=>'</li><!--box--><!--aside-->',
'before_title'=>'<h2>',
'after_title'=>'</h2>',
));
}
?>
So the output goes something like:
<div class="side">
<ul>
<li class="box">
<div class="textwidget">Lorem ipsum</div>
</li><!--box--><!--aside-->
<li class="box">
<h2>Blogroll</h2>
<ul class="xoxo blogroll">
<li><a href="http://example.com">Example</a></li>
</ul>
</li><!--box--><!--aside-->
</ul>
</div>
What I need is a conditional function so that any Links widget (or one with a class of .xoxo
) in the sidebars will not get a class of .box
because I want to style those and only those differently, and in a way that I can simply change certain styles from inside of .box
. The main problem is that I don’t know what function or variables to target with a filter. The codex doesn’t do a good job of classifying less-used global variables and I can’t see anything in the Filter Reference that looks like it should help.
I coded my own answer together using a filter and
dynamic_sidebar_params
:The first lines actually override whatever you programmed
register_sidebar()
orregister_sidebars()
to put before and after a widget. So you can safely leave that blank inregister_sidebar()
if you’re using this code. The first lines of the function make the name of the widget (therefore the type) a class of the list item and give a default class of.box
to all widgets. Theif
statement basically says, “If any of the widgets have the class.Links
(which they will if they’re a blogroll or linklist) change the XHTML list item tags before and after these widgets to use their widget name as their only class.”I hope this code helps a few people who are staring down the same question.
You can actually try that using jQuery.