I have a few default widgets which I am using in a custom sidebar and I’d like to edit its output in my functions.php file.

Currently the categories widget and blogrolls are generating an unordered list of links as such:

<ul>
<li class="cat-item cat-item-1">
<a href="http://localhost:8888/?cat=1">Uncategorized</a>
</li>
</ul>

I would like to somehow pass a class name into the unordered list itself to something along the lines of:

<ul class="test">...</ul>

I am just learning about using filters within the functions.php file and figured this was how I need to go about it but don’t really know how.. Is this possible? How could I find out how to do something like this?

— Bruno

3 Answers
3

Here is a little jQuery snippet I made that should do what you want it to do (this just works for the category widget):

// JavaScript Document
$j = jQuery.noConflict();
$j(document).ready(function(){
    $j('li.cat-item-1').parent().addClass('test');
});

If you wanted to do this to all widgets, well it depends on the parent element of the widgets. Let’s say there’s a <div class="widget"></div> wrapping each widget. You could do this to add the class to immediate child <ul>‘s of all widgets:

// JavaScript Document
$j = jQuery.noConflict();
$j(document).ready(function(){
    $j('.widget > ul').addClass('test');
});

However with PHP, that’s a different story.

Leave a Reply

Your email address will not be published. Required fields are marked *