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

I am using wp_list_categories to display all terms of my custom taxonomy 'categories'.

The function is outputting all my terms successfully but the current category is not being highlighted, even though 'current_category' is set to 1 in my arguments.

The function is being outputted on taxonomy-categories.php, following the naming convention of my taxonomy categories.

It is not inside a loop, could that be why?

UPDATE, here is my function:

$args = array(
    'orderby'               => 'term_group',
    'title_li'              =>  NULL,
    'order'                 => 'ASC',
    'hide_empty'            => 1,
    'use_desc_for_title'    => 0,
    'feed'                  => '',
    'hierarchical'          => 1,
    'echo'                  => 1,
    'current_category'      => 1,
    'taxonomy'              => 'categories'
echo wp_list_categories($args);

Note: this works on my single-{post-type}.php template, but does not function on my taxonomy-{taxonomy}.php template.

share|improve this question
You don't need to echo wp_list_categories($args) if you set the echo key to true. I would also try removing the current_category key entirely to see if that helps. It should by default, on the taxonomy template page display the current term from my understanding of it. Finally, the wp_list_categories() can be used anywhere be it inside or outside the loop. – Howdy_McGee Nov 11 '13 at 17:06
Bingo! You are right. Thank you. I never thought about the echo in my arguments. – Eoghan OLoughlin Nov 11 '13 at 17:14
up vote 0 down vote accepted

This will add a current-cat class to any / all categories connected to the post, not jut one.

Add this to functions.php

function tax_cat_active( $output, $args ) {

    global $post;

    $terms = get_the_terms( $post->ID, $args['taxonomy'] );
    foreach( $terms as $term )
        if ( preg_match( '#cat-item-' . $term ->term_id . '#', $output ) )
            $output = str_replace('cat-item-'.$term ->term_id, 'cat-item-'.$term ->term_id . ' current-cat', $output);

  return $output;
add_filter( 'wp_list_categories', 'tax_cat_active', 10, 2 );
share|improve this answer
Thank you, that did it. – Eoghan OLoughlin Nov 8 '13 at 16:56
This works perfectly on my single-{post-type}.php template. However I just realised it does not work on my taxonomy-{taxonomy}.php template. How can I get the same functionality on the taxonomy template? – Eoghan OLoughlin Nov 11 '13 at 12:49
For @Howdy_McGee – Eoghan OLoughlin Nov 11 '13 at 14:21
Could you post your wp_list_categories() code? It should have this functionality by default. – Howdy_McGee Nov 11 '13 at 14:47
I have updated the question with my code. – Eoghan OLoughlin Nov 11 '13 at 16:36

The answer provided by Howdy_McGee produced a PHP notice for me that prevented it from working correctly. I changed $terms = get_the_terms( $post->ID, $args['taxonomy'] ); to $terms = get_the_terms( $post->ID, 'taxonomy' ); I also added a check that the post has terms associated with it to suppress additional PHP warnings if $terms is empty.

function tax_cat_active($output, $args) {
    if (is_single()) {
        global $post;
        $terms = get_the_terms($post->ID, 'category');
        if (!empty($terms)) {
            foreach( $terms as $term )
                if ( preg_match( '#cat-item-' . $term ->term_id . '#', $output ) )
                    $output = str_replace('cat-item-'.$term ->term_id, 'cat-item-'.$term ->term_id . ' current-cat', $output);
    return $output;
add_filter('wp_list_categories', 'tax_cat_active', 10, 2); 
share|improve this answer

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.