How to Show Category Descriptions in WordPress

April 27, 2010

in Tutorials

Show Category Descriptions in Wordpress

You may have noticed on the Categories page in your WordPress dashboard that you can add a description to your categories. You may also notice that themes rarely employ this feature, which I find silly since it can add a nice touch to an archives page. So I’m going to show you how to use this little-used featured of WordPress. First are instructions for those using the Thesis theme, followed by instructions for most other themes.

For Thesis

If you’re not using the Thesis theme, skip past this section and find out how to show category descriptions in most other themes. If you are using Thesis, you’re in luck, because it’s very easy to show category descriptions on your archives pages without touching any original code.

  1. Put this in your custom-functions.php:
    function cat_desc (){
    if(is_category()){
    ?>
    <div class="catdesc"><?php echo category_description( $category ); ?></div>
    <?php } }
    add_action('thesis_hook_before_teasers_box', 'cat_desc');
    
  2. Add your category descriptions
  3. Navigate to the Categories section under Posts in the dashboard and add descriptions

Now if you’d like you can style your category descriptions by targeting .catdesc in custom.css if you’d like.

For other themes

For folk not using the Thesis theme, don’t fret! You can still add category descriptions very easily, there’s just a little bit more trial and error.

  1. Open up category.php if you have it, and archive.php if you don’t.
  2. Find the line that says single_cat_title();?
  3. Underneath it, add this:
    <div class="catdesc"><?php echo category_description( $category ); ?></div>
  4. Add your category descriptions in the admin panel under Categories > Posts

You can now style your descriptions as you see fit by targeting .catdesc in your options panel.

Note: See Category Templates << WordPress Codex for more information regarding editing category archives pages. Your category title may be wrapped in a class, so make sure to wait until the class is closed before placing your descriptions.

That’s it.

You’re done. Hopefully this worked for you and you can laugh in the face of “The description is not prominent by default”. If you have any problems, check with the Codex and then failing that leave a comment and hopefully I or one of our wonderful readers can help you out.

Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

You'll notice this site talks about the Thesis theme for Wordpress. Don't know what the heck that is? Find out.

{ 32 comments… read them below or add one }

designfollow April 29, 2010 at 6:46 pm

thank you for the great tutorial.

Reply

Stuart May 6, 2010 at 10:59 am

Hi Matt

Nice article! I have just started using the category description myself to lead the category articles, though ideally i would like to add mark-up to the description (h2 p classes etc.) though wordpress strips them out.

Do you know of any way to keep the mark up in place when wordpress outputs the description?

Any help would be appreciated!

Cheers
Stu

Reply

Matt Dunn May 6, 2010 at 12:33 pm

Yeah you can target p.catdesc in your css file to style the description text.

Reply

Stuart May 6, 2010 at 4:27 pm

Thanks for the reply Matt!

I had read about the p.catdesc, I was hoping to find something that allows me to put different text styles within the category description. I’m pretty sure now it isn’t possible but thanks for your help anyway

Cheers
Stu

Reply

Matt Dunn May 6, 2010 at 10:39 pm

No problem. Yeah, doing something like that I think would require creating a different function altogether I think. Good luck.

Reply

wpin May 8, 2010 at 2:49 pm

Came here from WPVote, very useful tutorial I suppose theoretically you could use a plugin to add tinymce to your category editing and physically show pictures and other useful info.

Retweeting now!!!

Reply

Stuart May 10, 2010 at 10:54 am

@wpin thanks for the tip, Ill try looking into that!
Ill keep you posted how i get on!

Stu

Reply

Jules May 20, 2010 at 10:35 pm

Appreciate the article. Is there a way to add the category description to the single.php page? I have it working just fine on archive.php, but when I try and get it to work on an actual post I get the following error:
Catchable fatal error: Object of class WP_Error could not be converted to string in …/single.php on line 18
Line 18 = echo category_description( $category );
I get a similar error if I exclude $category
Thanks! ~Jules

Reply

pondicherry May 30, 2010 at 10:35 am

thank you so much…. but i have one doubt how to show only parent category in page not child category

Reply

Dennis August 5, 2010 at 11:56 pm

Thanks, when I added your Thesis code I got a mouseover on each of the categories with the description, however it did not appear at the top of each respective category page. Is there a way to drop the mouseover and instead have it appear just under the category name, above the article listings?

Reply

Matt Dunn September 10, 2010 at 3:43 pm

This code isn’t supposed to be adding a mouseover; that happens automatically. The Thesis code is placing it above the category posts, under the category name, where you want it. You can try changing the hook to place it elsewhere.

Reply

Michèle August 13, 2010 at 2:51 pm

Hi Matt:
I did add the html code to the custom-functions.php of my Thesis theme site and clicked the save button. I made sure to have added the category description to two different categories: An Inside Look and Marketing Tips.

Nothing is showing up. Am I doing something wrong?

Thank you for coming up with a feature I would really like to take advantage of!

Reply

Matt Dunn September 10, 2010 at 3:52 pm

That’s odd. No, I’m not sure what could be going on – the code worked for me. =/ Check your other functions to make sure nothing’s formatted incorrectly or going wrong for them.

Reply

Alexandr Sarnavský September 1, 2010 at 8:35 pm

Thanks for your article. You really helped me.

Reply

Nick September 17, 2010 at 1:22 am

Hey Matt,
For some reason the description is showing up not only under the category name, but after every two posts. Any idea why it might show up more than once? Also, the description only shows up if I choose “Everything’s a teaser” under display options for archive pages. Is there a way to have this show up for other display options? Thanks!

Reply

Matt Dunn September 19, 2010 at 2:26 pm

Hm I don’t know why that’s happening. Are you sure the hook is correct? “Before Teasers Box” shows up before the box of teasers.

Reply

Stijn October 5, 2010 at 12:38 pm

IMHO this is something Thesis should include by default. Chris is always so strict when it comes to SEO, I cannot believe this still hasn’t been included. Don’t get me wrong, I’m a big fan of the theme, but in stead of making visual changes to the backend, how about adding some hardcore new features?

Reply

Christoph October 14, 2010 at 5:32 pm

Hi,

@Nick: Within the add_action argument use this hook: ‘thesis_hook_before_content’
The description then appears between title and content.

However, I have a question as well: Is there a way to execute PHP-code within the description field?

Best,
Chris

Reply

Brett Widmann November 21, 2010 at 2:21 am

This has been a really helpful and simple tutorial. Thanks for sharing.

Reply

Scott November 22, 2010 at 2:56 am

Would a similar code fix work for the addition of adding text in the Description field for Tag pages? The same issue is there. a Description field that does not seem to be used, even when populated.

Reply

Trasie Sands December 19, 2010 at 12:37 pm

Unfortunately ‘before_teasers_box’ puts it before each set of teasers, but after the feature box and certainly nowhere near the category title. Anybody have any ideas?

Reply

kate January 3, 2011 at 10:59 am

hi there
works perfect. But to make it even more perfect, is there a way to show category images in the description? I’m using taxonomy images for my categories, and description works fine but it doesn’t show pics. Any way to do this?
thanks
kat

Reply

Blogger February 24, 2011 at 12:59 pm

Kate – allowing html in the category description will allow you to embed images – this plugin should do the trick.

http://wordpress.org/extend/plugins/allow-html-in-category-descriptions/

Reply

Nick January 12, 2011 at 7:04 am

Exactly what I needed to know. Thanks!

Reply

matthew January 18, 2011 at 4:18 pm

Thank you so much for the article. I applied it, and it works perfectly. So now, I have Header page links that go to categories, with proper descriptions. Beautiful!!!
kate, I’m not sure if you mean, a picture to go with the category description; if you do, just grab the “allow html in category descriptions” plugin, and html code an image in.

http://wordpress.org/extend/plugins/allow-html-in-category-descriptions/

Reply

Heather April 5, 2011 at 12:38 am

Thanks for this! I was able to get it to work great!

One question, I’m still learning, I’m trying to style catdesc

I am assuming I target that on my custom style sheet correct?

This is what I have, but it doesn’t seem to affect the text at all?

I also have that plugin downloaded to allow html in categories,,

catdesc {
font-size: 14px;
}

Appreciate this! Thanks so much!

Reply

Vitaly September 3, 2011 at 5:27 am

Hi! I have no category.php, not archive.php and not the line “single_cat_title();?”. ((((

Reply

Pixelrage September 13, 2011 at 9:24 pm

I share Vitaly’s issue:
“Hi! I have no category.php, not archive.php and not the line “single_cat_title();?””

Reply

meg September 5, 2011 at 9:39 pm

Hi Matt-

Thanks for this article. Is there a way to insert/display an additional description field for category pages? I need to have an area to add/display text *below* the posts that appear on category pages (in addition to the description field which I have displaying at the top of the page).

Thanks!
Meg

Reply

Rachel October 19, 2011 at 11:34 am

Thanks so much for this, I’ve been trying to add category descriptions to the theme I’m using for an hour, your advice was simple to follow and worked!

Cheers :)

Reply

Web Design Dunshaughlin December 13, 2011 at 3:20 pm

Great and thanks very much for this simple tutorial.

Reply

Crushers January 4, 2012 at 12:26 am

This is what I’m looking for, good work!

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: