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 ); ?>
Here’s a quick example. I filled out my category description field and then I placed the code above in my archive.php file.
Using HTML in Your Category Description
By default you cannot use HTML in your category description field. 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)
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.Tags: