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

Inside the category.php file I have a custom navbar which is...

<ul class = "nav nav-tabs nav-justified">
                <li><a href="http://example.com/blog/" title="View all posts">All Categories</a></li>
                <?php wp_list_categories('orderby=name&title_li='); ?>

I would like the li for the current category to have class = "active". How can I code this?

Thank you

share|improve this question
The current category link has already a special class: current-cat. Why don’t you just use that? – toscho Feb 8 '14 at 23:42
as I am using bootstrap framework which uses active not current. – ijames55 Feb 8 '14 at 23:43
open bootstrap, look at class 'active' and copy it naming if 'current'. Really, it works. – gmazzap Feb 9 '14 at 1:19
up vote 0 down vote accepted

You can filter the output on wp_list_categories:

add_filter( 'wp_list_categories', function( $html ) {
    return str_replace( ' current-cat', ' active', $html );

If you are stuck with an outdated PHP version … find a better web hosting. In the mean time, you can try this:

add_filter( 'wp_list_categories', 'replace_current_cat_css_class' );

function replace_current_cat_css_class( $html ) {
    return str_replace( ' current-cat', ' active', $html );
share|improve this answer
Sorry for being a noob but where do I put this code?? – ijames55 Feb 9 '14 at 0:05
In your theme’s functions.php. – toscho Feb 9 '14 at 0:06
I'm getting Parse error: syntax error, unexpected T_FUNCTION in /home/a8346489/public_html/wp-content/themes/bootstrap/functions.php on line 9 – ijames55 Feb 9 '14 at 0:19
@ijames55 Your PHP version is very old and insecure. Please do yourself a favor and run an upgrade immediately. My script will work then. – toscho Feb 9 '14 at 0:26
Wow, didn't realise how old it was, I guess free web hosting is free for a reason... Is there any way to get round this? – ijames55 Feb 9 '14 at 0:28

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.