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.

Compatibility

WordPress
since 6.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

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 value

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

Performance profile

How much work a call to wp_list_categories() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_terms().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
82–160

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 259.

Plugin surface
1 hook

Third-party callbacks on 'wp_list_categories' run inside this call, and their cost is not bounded by anything here.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • querycontent queryget_terms()one call below wp_list_categories()
  • cacheobject cachewp_cache_get()one call below wp_list_categories()
  • serializeserialisationmaybe_unserialize()one call below wp_list_categories()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 40 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_list_categories() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && !empty($parsed_args)82–92__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && empty($parsed_args) && is_category()89–103__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), is_category(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && !is_tag()91–101__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), is_category(), is_tax(), is_tag(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && empty($parsed_args) && !is_category() && is_tax()92–106__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), is_category(), is_tax(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && is_tag()95–109__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), is_category(), is_tax(), is_tag(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && empty($parsed_args) && is_category()97–107__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), is_category(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && empty($parsed_args) && !is_category() && is_tax()100–110__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), is_category(), is_tax(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && is_tag()103–113__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), is_category(), is_tax(), is_tag(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !empty($parsed_args)107–125__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && is_category()114–135__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), is_category(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !empty($parsed_args)116–131__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && !is_tag()116–133__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), is_category(), is_tax(), is_tag(), walk_category_tree(), apply_filters()
28 further outcomes, up to 160 instructions
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && is_tax()117–138__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), is_category(), is_tax(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && !empty($parsed_args)120–135__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && is_tag()120–141__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && is_category()122–139__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), is_category(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && is_category()123–142__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), is_category(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && !empty($parsed_args)124–139__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && is_tax()125–142__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), is_category(), is_tax(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && !is_tag()125–140__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), is_category(), is_tax(), is_tag(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && is_tax()126–145__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), is_category(), is_tax(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && empty($parsed_args) && is_category()127–146__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), is_category(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && is_tag()128–145__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && is_tag()129–148__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && empty($parsed_args) && !is_category() && !is_tax() && !is_tag()129–144__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), is_category(), is_tax(), is_tag(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && empty($parsed_args) && !is_category() && is_tax()130–149__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), is_category(), is_tax(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && is_category()131–146__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), is_category(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && empty($parsed_args) && is_category()131–150__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), is_category(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && empty($parsed_args) && !is_category() && !is_tax() && is_tag()133–152__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && empty($parsed_args) && !is_category() && !is_tax() && !is_tag()133–148__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), is_category(), is_tax(), is_tag(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && is_tax()134–149__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), is_category(), is_tax(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && empty($parsed_args) && !is_category() && is_tax()134–153__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), is_category(), is_tax(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && empty($parsed_args) && is_category()135–150__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), is_category(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && empty($parsed_args) && !is_category() && !is_tax() && is_tag()137–152__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), home_url(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && empty($parsed_args) && !is_category() && !is_tax() && is_tag()137–156__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && empty($parsed_args) && !is_category() && is_tax()138–153__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), is_category(), is_tax(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && empty($parsed_args) && is_category()139–154__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), is_category(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && !get_option() && empty($parsed_args) && !is_category() && !is_tax() && is_tag()141–156__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), home_url(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && empty($parsed_args) && !is_category() && is_tax()142–157__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), is_category(), is_tax(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()
isset($parsed_args) && !$parsed_args && taxonomy_exists() && !empty($categories) && !empty($show_option_all) && get_option() && empty($parsed_args) && !is_category() && !is_tax() && is_tag()145–160__(), __(), wp_parse_args(), taxonomy_exists(), get_categories(), get_taxonomy(), get_option(), get_option(), get_option(), get_permalink(), esc_url(), is_category(), is_tax(), is_tag(), get_queried_object(), get_queried_object_id(), walk_category_tree(), apply_filters()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev25982–16038
8.525982–16038
8.425982–160386 fewer instructions than PHP 8.3
8.326582–16638
8.226582–16638
8.126582–166381 fewer instruction than PHP 7.4
7.426682–16638

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters 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 code

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 ) ) {

Changelog

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 7.1.0 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.