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

In a site I have using Wordpress 3.0, when I'm in a single post, the navbar showing the categories doesn't give the parent category the class of "current_cat" and therefore that category is not highlighted.

How can I make Wordpress give the parent category that class in single_post mode?

share|improve this question
up vote 5 down vote accepted

I found the answer here.
Add to functions.php the following function and hook:

function sgr_show_current_cat_on_single($output) {

global $post;

if( is_single() ) {

    $categories = wp_get_post_categories($post->ID);

    foreach( $categories as $catid ) {
        $cat = get_category($catid);
        // Find cat-item-ID in the string
        if(preg_match('#cat-item-' . $cat->cat_ID . '#', $output)) {
            $output = str_replace('cat-item-'.$cat->cat_ID, 'cat-item-'.$cat->cat_ID . ' current-cat', $output);

return $output;

add_filter('wp_list_categories', 'sgr_show_current_cat_on_single');
share|improve this answer
Very good information. Choose your your answer as the best so this will show as an answered question. – Chris_O Sep 21 '10 at 0:16

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.