How to Display Your WordPress Category Description in Your Theme

How to Display Your WordPress Category Description in Your Theme


Maybe one of the least used functions in all of WordPress is the Category Description.

Many of you may be saying, “The what?”

Although it may not sound familiar, you’ve probably seen the field for the category description countless times. It’s that box that most of us skip over when we’re setting up or editing our categories.

If you fill that box in, however, you can then display what’s written in it with the following piece of code (provided your theme doesn’t already use the category description function, as many don’t). Just put this in your theme wherever you’d like – for example, at the top of your category template (usually category.php or archive.php).

<?php echo category_description( $category_id ); ?>

An Example

Here’s a quick example. I filled out my category description box, and then I placed the code above in my archive.php file.

 

Use HTML in Your Category Description

By default you cannot use HTML in your category description box. However, there is a workaround for that. Simply put the following in your functions.php file after the opening <? php. (Appearance > Editor > Theme Functions – functions.php)

remove_filter('pre_term_description', 'wp_filter_kses');

Once you’ve done that, you can insert whatever HTML you like in your description box. Here’s an example of a headline, an image, and wrapped text at the top of a category page.

 

Why Use a Category Description

Not everyone will need or want a category description, but it may be able to liven up your site (especially if you use HTML), give your users useful information, and of course, it may even help out the SEO of your category pages.

Photo: Urban graffiti Boy. Vector Cartoon from BigStock