The wp_list_categories() WordPress PHP function displays or retrieves an HTML list of categories.
Usage
wp_list_categories( $args ); // your custom code here
Parameters
$args
(array|string) (Optional): Array of optional arguments. Seeget_categories()
,get_terms()
, andWP_Term_Query::__construct()
for information on additional accepted arguments.current_category
(int|int[]): ID of category, or array of IDs of categories, that should get the ‘current-cat’ class. Default 0.depth
(int): Category depth. Used for tab indentation. Default 0.echo
(bool|int): Whether to echo or return the generated markup. Accepts 0, 1, or their bool equivalents. Default 1.
Returns
Void if ‘echo’ argument is true, HTML list of categories if ‘echo’ is false. False if the taxonomy does not exist.
More information
See WordPress Developer Resources: wp_list_categories()
If you need a function that does not format the results, try get_categories()
.
Examples
Display categories in a simple unordered list
This example displays categories in a simple unordered list without any extra information.
wp_list_categories( array( 'style' => 'list', ) );
Display categories with post count
This example displays categories with post count.
wp_list_categories( array( 'show_count' => 1, ) );
Exclude specific categories
This example excludes categories with IDs 5 and 15.
wp_list_categories( array( 'exclude' => '5, 15', ) );
Display categories as a dropdown menu
This example displays categories as a dropdown menu.
wp_dropdown_categories();
Display categories as links separated by a comma
This example displays categories as links separated by a comma.
wp_list_categories( array( 'style' => '', 'separator' => ', ', ) );