Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

wp_list_bookmarks returns HTML that has a ul with classes xoxo blogroll. I'd like to add another class to that ul, but can't seem to find an elegant way to do so.

wp_list_bookmarks does accept an argument "class", but that is applied to the li, not the ul. Is there some argument I'm missing? Or is there a hook I can hook onto and add a class?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

There is a filter 'wp_list_bookmarks' for the complete markup. You can use it:

add_filter( 'wp_list_bookmarks', 'wpse40213_new_classes', 10, 1 );

function wpse40213_new_classes( $html )
{
    return str_replace( "class='xoxo blogroll'", "class='my_bookmarks blogroll'", $html );
}
share|improve this answer
    
Thank you. I was thinking in the direction of string replacing. But why should I do it with a filter? What's the difference between that, and doing: $str=wp_list_bookmarks('echo=0'); echo str_replace( "class='xoxo blogroll'", "class='my_bookmarks blogroll'", $str); ? –  Lea Cohen Jan 26 '12 at 7:52
    
There is no big difference. The filter will run always, no matter where and how often you call wp_list_bookmarks(). Plus, a child theme could remove or replace the filter. –  toscho Jan 26 '12 at 7:58

Your Answer

 
discard

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.