wppaste
WordPress

wp_list_categories( array|string $args = '' ): void|string|false

Since
2.1.0, 4.4.0, 4.4.0, 6.1.0
Source
wp-includes/category-template.php:538
Displays or retrieves the HTML list of categories.

Parameters

$argsarray|stringoptional
Array of optional arguments. See get_categories(), get_terms(), and WP_Term_Query::__construct() for information on additional accepted arguments.Default: ''
  • $current_categoryint|int[]default: 0

    ID of category, or array of IDs of categories, that should get the 'current-cat' class.
  • $depthintdefault: 0

    Category depth. Used for tab indentation.
  • $echobool|intdefault: 1

    Whether to echo or return the generated markup. Accepts 0, 1, or their bool equivalents.
  • $excludeint[]|stringdefault: empty string

    Array or comma/space-separated string of term IDs to exclude. If $hierarchical is true, descendants of $exclude terms will also be excluded; see $exclude_tree. See get_terms().
  • $exclude_treeint[]|stringdefault: empty string

    Array or comma/space-separated string of term IDs to exclude, along with their descendants. See get_terms().
  • $feedstringdefault: 'Feed for all posts filed under [cat name]'

    Text to use for the feed link.
  • $feed_imagestringdefault: empty string

    URL of an image to use for the feed link.
  • $feed_typestringdefault: empty string (default feed)

    Feed type. Used to build feed link. See get_term_feed_link().
  • $hide_title_if_emptybooldefault: false (title will always be shown)

    Whether to hide the $title_li element if there are no terms in the list.
  • $separatorstringdefault: ' '

    Separator between links.
  • $show_countbool|intdefault: 0

    Whether to include post counts. Accepts 0, 1, or their bool equivalents.
  • $show_option_allstringdefault: empty string

    Text to display for showing all categories.
  • $show_option_nonestringdefault: 'No categories'

    Text to display for the 'no categories' option.
  • $stylestringdefault: 'list'

    The style used to display the categories list. If 'list', categories will be output as an unordered list. If left empty or another value, categories will be output separated by <br> tags.
  • $taxonomystringdefault: 'category'

    Name of the taxonomy to retrieve.
  • $title_listringdefault: 'Categories'

    Text to use for the list title <li> element. Pass an empty string to disable.
  • $use_desc_for_titlebool|intdefault: 0

    Whether to use the category description as the title attribute. Accepts 0, 1, or their bool equivalents.
  • $walkerWalkerdefault: empty which results in a Walker_Category instance being used

    Walker object to use to build the output.

Return

void|string|false
Void if 'echo' argument is true, HTML list of categories if 'echo' is false. False if the taxonomy does not exist.

Hooks fired · 1

One hook fires while wp_list_categories() runs, in this order:

  1. apply_filters( wp_list_categories )filterline 681 (+143 into the body)

    Filters the HTML output of a taxonomy list.

Uses · 20

Show all 20

Used by · 3

Source

function wp_list_categories( $args = '' ) {	$defaults = array(		'child_of'            => 0,		'current_category'    => 0,		'depth'               => 0,		'echo'                => 1,		'exclude'             => '',		'exclude_tree'        => '',		'feed'                => '',		'feed_image'          => '',		'feed_type'           => '',		'hide_empty'          => 1,		'hide_title_if_empty' => false,		'hierarchical'        => true,		'order'               => 'ASC',		'orderby'             => 'name',		'separator'           => '<br />',		'show_count'          => 0,		'show_option_all'     => '',		'show_option_none'    => __( 'No categories' ),		'style'               => 'list',		'taxonomy'            => 'category',		'title_li'            => __( 'Categories' ),		'use_desc_for_title'  => 0,	); 	$parsed_args = wp_parse_args( $args, $defaults ); 	if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) {		$parsed_args['pad_counts'] = true;	} 	// Descendants of exclusions should be excluded too.	if ( $parsed_args['hierarchical'] ) {		$exclude_tree = array(); 		if ( $parsed_args['exclude_tree'] ) {			$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude_tree'] ) );		} 		if ( $parsed_args['exclude'] ) {			$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude'] ) );		} 		$parsed_args['exclude_tree'] = $exclude_tree;		$parsed_args['exclude']      = '';	} 	if ( ! isset( $parsed_args['class'] ) ) {		$parsed_args['class'] = ( 'category' === $parsed_args['taxonomy'] ) ? 'categories' : $parsed_args['taxonomy'];	} 	if ( ! taxonomy_exists( $parsed_args['taxonomy'] ) ) {		return false;	} 	$show_option_all  = $parsed_args['show_option_all'];	$show_option_none = $parsed_args['show_option_none']; 	$categories = get_categories( $parsed_args ); 	$output = ''; 	if ( $parsed_args['title_li'] && 'list' === $parsed_args['style']		&& ( ! empty( $categories ) || ! $parsed_args['hide_title_if_empty'] )	) {		$output = '<li class="' . esc_attr( $parsed_args['class'] ) . '">' . $parsed_args['title_li'] . '<ul>';	} 	if ( empty( $categories ) ) {		if ( ! empty( $show_option_none ) ) {			if ( 'list' === $parsed_args['style'] ) {				$output .= '<li class="cat-item-none">' . $show_option_none . '</li>';			} else {				$output .= $show_option_none;			}		}	} else {		if ( ! empty( $show_option_all ) ) {

History

Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.1.0
Default value of the 'use_desc_for_title' argument was changed from 1 to 0.from the docblock
4.4.0
The current_category argument was modified to optionally accept an array of values.from the docblock
4.4.0
Introduced the hide_title_if_empty and separator arguments.from the docblock
2.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/category-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.