In 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.
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.
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.
But tags do have descriptions too – can I make it work for tags ?
I’m not aware of descriptions for tags – got a pointer to where it is documented in the codex?