WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(
    'id'  =>'sidebar',
    'before_widget'=>'<li class="box">',

So the output goes something like:

<div class="side">
  <li class="box">
   <div class="textwidget">Lorem ipsum</div>
  <li class="box">
   <ul class="xoxo blogroll">
   <li><a href="http://example.com">Example</a></li>

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.

share|improve this question
Take a look at the question at the very top of the related links to the righthand side of this page(Mike's answer specifically) and see if anything there helps. – t31os Nov 30 '11 at 17:16
Thanks! Very helpful. See my answer below. – Iterate Dec 9 '11 at 3:24
up vote 2 down vote accepted

I coded my own answer together using a filter and dynamic_sidebar_params:



function io_blogroll_class($params){
 $params[0]['before_widget'] =  '<li class="'.$params[0]['widget_name'].' box">';
 $params[0]['after_widget'] =  '</li><!--'.$params[0]['widget_name'].'-->';

    if ($params[0]['widget_name'] == "Links"){
$params[0]['before_widget'] =  '<li class="'.$params[0]['widget_name'].'">';
 $params[0]['after_widget'] =  '</li><!--'.$params[0]['widget_name'].'-->';
return $params;


The first lines actually override whatever you programmed register_sidebar() or register_sidebars()to put before and after a widget. So you can safely leave that blank in register_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. The if 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.

share|improve this answer

You can actually try that using jQuery.

share|improve this answer
It's not a bad suggestion, but if it really came to that, I'd just list CSS selectors for the default widgets and make a faster page. But this should be possible with the WP API. – Iterate Nov 30 '11 at 7:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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