Home WordPress Category Functions category_description() WordPress category_description() Function 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.
category_description();
category_description( 5 );
$text = category_description(); Call What 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 category_description( int $category = 0 ): string Parameters Parameter Description $categoryOptional. The category ID. Default 0, which means the current category on an archive page.
Return Value Return Value Description string The category description. It may contain basic HTML such as <p>. empty string The category has no description, or the ID is not valid.
WordPress Examples Three short theme examples. Each one has a sample output.
1. Current category 2. By category ID 3. Check first Example 1 — Current category Print the description on a category archive page.
<?php
echo category_description();
?> <p>Tips, guides, and news about WordPress.</p> How It Works On a category archive, WordPress knows the current category. category_description() returns the saved description.echo prints it on the page.Example 2 — By category ID Show the description of a specific category.
<?php
echo category_description( 5 );
?> <p>Short tutorials for beginners.</p> How It Works The number 5 is the category ID. The function returns the description of that category. This works on any page, not only on archives. Example 3 — Check before printing Only show the box when the description is not empty.
<?php
$text = category_description();
if ( $text ) {
echo '<div class="archive-description">' . $text . '</div>';
}
?> <div class="archive-description"><p>Tips, guides, and news about WordPress.</p>
</div> How It Works The description is saved in $text. An empty string is false, so an empty box is never printed. The wrapper div can be styled in your CSS. Frequently Asked Questions What does category_description() return? It returns the description of a category as a string. The default is the current category on a category archive page.
Does category_description() print the text? No. It returns the text. Use echo to print it.
Where do I write a category description? In the WordPress admin, go to Posts > Categories, edit a category, and fill in the Description field.
What is the difference between category_description() and term_description()? category_description() is a wrapper for categories. term_description() works for any term, such as tags and custom taxonomies.
Should I escape the description? 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().
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion