WordPress category_description() Function

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

Definition

In WordPress, category_description() returns the description of a category. On a category archive page it reads the current category. You can also pass a category ID.

It returns the text as a string. It does not print it, so use echo to show it. It is a small wrapper around term_description().

Syntax

Call it with no argument on a category archive, or pass a category ID.

WordPress
category_description();
category_description( 5 );
$text = category_description();
CallWhat it does
category_description()Returns the description of the current category.
category_description( 5 )Returns the description of the category with ID 5.
$text = category_description()Saves the description in a variable so you can test it first.

Add the description in category.php or archive.php under the archive title.

Full declaration
WordPress
category_description( int $category = 0 ): string

Parameters

ParameterDescription
$categoryOptional. The category ID. Default 0, which means the current category on an archive page.

Return Value

Return ValueDescription
stringThe category description. It may contain basic HTML such as <p>.
empty stringThe category has no description, or the ID is not valid.

WordPress Examples

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

Example 1 — Current category

Print the description on a category archive page.

WordPress
<?php
echo category_description();
?>

How It Works

  1. On a category archive, WordPress knows the current category.
  2. category_description() returns the saved description.
  3. echo prints it on the page.

Example 2 — By category ID

Show the description of a specific category.

WordPress
<?php
echo category_description( 5 );
?>

How It Works

  1. The number 5 is the category ID.
  2. The function returns the description of that category.
  3. This works on any page, not only on archives.

Example 3 — Check before printing

Only show the box when the description is not empty.

WordPress
<?php
$text = category_description();
if ( $text ) {
  echo '<div class="archive-description">' . $text . '</div>';
}
?>

How It Works

  1. The description is saved in $text.
  2. An empty string is false, so an empty box is never printed.
  3. The wrapper div can be styled in your CSS.

Frequently Asked Questions

It returns the description of a category as a string. The default is the current category on a category archive page.
No. It returns the text. Use echo to print it.
In the WordPress admin, go to Posts > Categories, edit a category, and fill in the Description field.
category_description() is a wrapper for categories. term_description() works for any term, such as tags and custom taxonomies.
The text can contain HTML, so esc_html() would show the tags as text. WordPress already filters it. If you want extra safety, use wp_kses_post().

Next: get_the_term_list()

Return linked terms of a post for any taxonomy as one HTML string.

get_the_term_list() 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