Showing the WordPress category description on your theme

July 1, 2012 / WordPress / By Kathy Alice

WordPress how toIn my quest to make my category pages index worthy, last week I added manual excerpts to my WordPress archive pages. This week I altered my WordPress code to show category descriptions on the category pages, adding yet more unique content to these pages. Your theme might show these category descriptions out of the box, but most don’t, including mine. Here’s what I did: step by step.

Step 1: Update your category name and description

Before you alter your theme to show the category description on your category pages, make sure you have something to show. Click on the “Categories” menu item in the WordPress admin and then add a category description as I have done below. You may want to also pick a more “catchy” name for your category.

Edit WordPress Category to add Description
Edit WordPress Category to add Description

Step 2: Update your theme to show the category descriptions

As I mentioned above, most WordPress themes do not show the category descriptions on the category pages, but some do, so it’s worth a quick check to see if your descriptions are showing. If so, you are done! If not, read on.

We will be updating the same file we updated last week archive.php. As before, you need to be comfortable with updating code and uploading files to your web server. The archive.php file has a number of if statements determining what type of archive page we are dealing with, so find the if block
if (is_category()) as you only want to modify the code for the category archives (tags don’t have descriptions). You’ll see a line of code that prints out (using printf or echo) the category name, you may want to modify that so instead of “Posts in Category X” it just displays your sexy new category name. Underneath that you will want to add the following code:
<?php echo category_description( $category_id ); ?>

Upload your file and your category descriptions should now be displaying.

Note: You may need to add some formating around the above code to get it to display in a good looking font and style. This will be dependent on your theme’s CSS. One hack to try is to display it within h2 or h3 tags.

About the Author Kathy Alice

Kathy Alice Brown is a SEO expert specializing in Technical SEO and Content. In her spare time she loves to get outside.

Leave a comment:

Your email address will not be published. Required fields are marked

  1. A better file to update is category.php rather archive.php. Making the changes in category.php will limit the changes to just category pages.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Related Posts