WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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
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


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.