Set Current Category to Active in category.php

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='); ?>
            </ul>

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

Read More

Thank you

Related posts

1 comment

  1. 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 );
    }
    

Comments are closed.