# Category List Shortcode

> Adds a [category_list] shortcode that prints a linked list of your categories, optionally with post counts and nested subcategories.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: shortcode, categories, navigation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/category-list-shortcode/

## Code

```php
add_shortcode( 'category_list', function ( $atts ) {
    $atts = shortcode_atts( array(
        'show_count'   => 'no',
        'hierarchical' => 'yes',
        'exclude'      => '',
        'taxonomy'     => 'category',
    ), $atts, 'category_list' );

    $list = wp_list_categories( array(
        'title_li'     => '',
        'echo'         => false,
        'show_count'   => 'yes' === $atts['show_count'],
        'hierarchical' => 'yes' === $atts['hierarchical'],
        'exclude'      => wp_parse_id_list( $atts['exclude'] ),
        'taxonomy'     => taxonomy_exists( $atts['taxonomy'] ) ? $atts['taxonomy'] : 'category',
    ) );

    return '<ul class="wpide-category-list">' . $list . '</ul>';
} );
```

## Notes

Example: [category_list show_count="yes" exclude="1,7" taxonomy="category"].

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Category List Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
