Title: Adding category count
Last modified: July 2, 2023

---

# Adding category count

 *  Resolved [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/adding-category-count-2/)
 * How could I add the number of posts for each category (in parenthesis) starting
   from this code (in archive.php):
 *     ```wp-block-code
       <?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?>
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-category-count-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/adding-category-count-2/#post-16863272)
 * Try this one:
 *     ```wp-block-code
       function custom_add_count_on_archive_title( $title ) {
        $term = get_queried_object();
        if( $term instanceof WP_Term && 'category' === $term->taxonomy ) {
         $title .= ' ('.$term->count.')';
        }
        return $title;
       }
       add_filter( 'get_the_archive_title', 'custom_add_count_on_archive_title', 10, 1 );
       ```
   
 * Add this in the functions.php of your child-theme or via Code Snippet-plugin.
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/adding-category-count-2/#post-16863289)
 * It works, thank you. Maybe is it possible to style the number and the parethesis
   by css?
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/adding-category-count-2/#post-16863300)
 * Replace
 *     ```wp-block-code
       $title .= ' ('.$term->count.')';
       ```
   
 * with
 *     ```wp-block-code
       $title .= ' <span>('.$term->count.')</span>';
       ```
   
 * and you should be able to style it via CSS, e.g.:
 *     ```wp-block-code
       .page-title span { color: red; }
       ```
   
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/adding-category-count-2/#post-16863315)
 * Everything is working:)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding category count’ is closed to new replies.

## Tags

 * [category count](https://wordpress.org/support/topic-tag/category-count/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [sacconi](https://wordpress.org/support/users/sacconi/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/adding-category-count-2/#post-16863315)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
