WordPress wp_dropdown_categories() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, wp_dropdown_categories() builds an HTML select box of categories. Visitors can pick one category from the list.

It prints the select box by default and also returns the HTML string. Set echo to 0 if you only want the string.

Syntax

Pass an array of arguments. Every argument is optional.

WordPress
wp_dropdown_categories();
wp_dropdown_categories( array(
  'show_option_all' => 'All Categories',
  'name'            => 'cat',
) );
CallWhat it does
wp_dropdown_categories()Prints a select box with the default settings.
wp_dropdown_categories( array( 'show_option_all' => 'All Categories' ) )Adds a first option for all categories.
$html = wp_dropdown_categories( array( 'echo' => 0 ) )Returns the HTML instead of printing it.

Put the select box inside a form so the choice can be sent.

Full declaration
WordPress
wp_dropdown_categories( array|string $args = '' ): string

Parameters

ParameterDescription
show_option_allOptional. Text for a first option that means all categories. Default is empty.
nameOptional. The name of the select field. Default is cat.
selectedOptional. The ID of the category that is selected. Default is 0.
hierarchicalOptional. 1 shows child categories under their parents. Default is 0.
orderbyOptional. Sort by id, name, count, and more. Default is id.
hide_emptyOptional. 1 hides categories without posts. Default is 1.
taxonomyOptional. The taxonomy to list. Default is category.
echoOptional. 1 prints the HTML. 0 does not print it. Default is 1.

Return Value

Return ValueDescription
stringThe HTML of the select box. It is also printed when echo is 1.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Basic drop-down

Print a select box with an All Categories option.

WordPress
<?php
wp_dropdown_categories( array(
  'show_option_all' => 'All Categories',
) );
?>

How It Works

  1. show_option_all adds the first option.
  2. Each category becomes an option with its ID as the value.
  3. The select box is printed because echo is on by default.

Example 2 — In a form

Send the visitor to the chosen category.

WordPress
<form action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
  <?php
  wp_dropdown_categories( array(
    'show_option_all' => 'Choose a category',
    'name'            => 'cat',
  ) );
  ?>
  <button type="submit">Go</button>
</form>

How It Works

  1. The form sends a GET request to the home page.
  2. The field name cat is a built-in WordPress query variable.
  3. WordPress opens the category archive for the chosen ID.

Example 3 — Return the HTML

Save the select box in a variable and pre-select a category.

WordPress
<?php
$dropdown = wp_dropdown_categories( array(
  'echo'     => 0,
  'selected' => 3,
) );
echo '<p>' . $dropdown . '</p>';
?>

How It Works

  1. 'echo' => 0 returns the HTML and does not print it.
  2. 'selected' => 3 marks category 3 as selected.
  3. You can now wrap the HTML in your own tags.

Frequently Asked Questions

It builds an HTML select box (drop-down) that lists categories.
It does both by default. Set echo to 0 to only return the HTML.
Use the show_option_all argument, for example 'show_option_all' => 'All Categories'.
By default hide_empty is on. Categories with no posts are hidden. Use 'hide_empty' => 0 to show them.
Yes. Use the taxonomy argument, for example 'taxonomy' => 'post_tag'. Set 'name' to match the query variable you need.

Next: wp_generate_tag_cloud()

Build tag cloud HTML from an array of term objects.

wp_generate_tag_cloud() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful