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
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: 0ID of category, or array of IDs of categories, that should get the 'current-cat' class.$depthintdefault: 0Category depth. Used for tab indentation.$echobool|intdefault: 1Whether to echo or return the generated markup. Accepts 0, 1, or their bool equivalents.$excludeint[]|stringdefault: empty stringArray or comma/space-separated string of term IDs to exclude. If$hierarchicalis true, descendants of$excludeterms will also be excluded; see$exclude_tree. See get_terms().$exclude_treeint[]|stringdefault: empty stringArray 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 stringURL 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_lielement if there are no terms in the list.$separatorstringdefault: ' 'Separator between links.$show_countbool|intdefault: 0Whether to include post counts. Accepts 0, 1, or their bool equivalents.$show_option_allstringdefault: empty stringText 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: 0Whether 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 usedWalker 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:
- apply_filters( wp_list_categories )filterline 681 (+143 into the body)
Filters the HTML output of a taxonomy list.
Uses · 20
- __()Retrieves the translation of $text.
- wp_parse_args()Merges user defined arguments into defaults array.
- wp_parse_id_list()Cleans up an array, comma- or space-separated list of IDs.
- taxonomy_exists()Determines whether the taxonomy name exists.
- get_categories()Retrieves a list of category objects.
- esc_attr()Escaping for HTML attributes.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- get_post_type_object()Retrieves a post type object by name.
- get_post_type_archive_link()Retrieves the permalink for a post type archive.
- get_option()Retrieves an option value based on an option name.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- home_url()Retrieves the URL for the current site where the front end is accessible.
Show all 20
- esc_url()Checks and cleans a URL.
- is_category()Determines whether the query is for an existing category archive page.
- is_tax()Determines whether the query is for an existing custom taxonomy archive page.
- is_tag()Determines whether the query is for an existing tag archive page.
- get_queried_object()Retrieves the currently queried object.
- get_queried_object_id()Retrieves the ID of the currently queried object.
- walk_category_tree()Retrieves HTML list content for category list.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 3
- WP_Widget_Categories::widget()Outputs the content for the current Categories widget instance.
- render_block_core_categories()Renders the `core/categories` block on server.
- wp_list_cats()Lists categories.
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.
Signature, return type and hooks compared across 5 parsed releases.
current_category argument was modified to optionally accept an array of values.from the docblockhide_title_if_empty and separator arguments.from the docblockAbout 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.