How to Show Category and Tag Descriptions In WordPress Theme

WordPress lets you add a short description to the categories as well as to the post tags of your blog. Here is a brief tutorial to show the category and tag descriptions in your WordPress theme.

Why category and tag descriptions? You may ask. Adding descriptions to category and tag pages has two advantages. First, the reader of your blog can have a rough idea on the type of posts are covered in a particular category. Second, you can show the category and tag descriptions as meta description on the respective pages which may help for better SEO. (see example)

Show Category Description in Category Pages Of WordPress Theme

1. First, add a description to your categories from WordPress Dashboard > Categories.

Add description to categories in WordPress
2.  Open your FTP client, browse to your WordPress theme directory and download the archive.php file for editing. Better, create a backup of the archive.php file to be safe.

3. You will see a code block like the following:

Add category description in WordPress category pages

4. Paste the following code just below it.

<?php if (is_category()) { ?>
<?php $description=category_description(); echo $description;  ?>
<?php } ?>

The above code pulls the category description that you entered in step 1 and displays the same to the user.

5. For the meta description part, add the following code before the </head> tag in your WordPress theme.

<?php
if (is_category()) { ?>
<meta name=”description” content=”<?php $description=category_description(); echo $description;  ?>” />
<?php } ?>

Note: Using All in one Seo pack plugin may override the above code.

Show Tag Descriptions in Tag Pages Of WordPress Theme

To show the tag descriptions, follow steps 1, 2 and 3 as described in previous section and then continue with what follows next.

4. Paste the following code to show tag descriptions in every tag page.

<?php if (is_tag()) { ?><?php echo tag_description(); ?><?php } ?>

You do not need to fill out each and every tag to use the above code. If a tag does not have any description, the above code shows nothing. (see example)

5. To display the tag descriptions as meta descriptions, put the following code before </head> in your WordPress theme.

<?php if ( is_tag() && tag_description() ) : ?>
<meta name=”description” content=”<?php echo wp_specialchars( strip_tags( tag_description() ), 1 ); ?>” />
<?php endif; ?>

Tip: How to show meta description as post excerpts in blog’s index page.

Styling Category and Tag descriptions

To style the category and tag descriptions, all you have to do is include a unique class just before the description field.

For example:

<?php if (is_tag()) { ?><div class=”yourclassname”><?php echo tag_description(); ?></div><?php } ?>

Now, write the attributes of the div class in the style.css file of your WordPress theme.

Would love to hear your thoughts on the topic.

Email this article

Written by on Wednesday, February 10th, 2010

  1. Reader Comments

  2. Tony

    I searched on how to add Category Descriptions, this page came up, and the instructions were really easy to follow.
    Thanks very much, I am hoping that this will help improve the SEO ranking of the Category and Tag pages on my sites, if only slightly.

    March 5th, 2010
  3. Amit Banerjee

    Thanks Tony for your comment. Adding category and Tag descriptions is not a must, but may help in SEO and above all it serves the user.

    March 5th, 2010
  4. Matt Halfhill

    Thank you for the informative post!

    I was wondering if you know how to echo images, links, and other html with the tag_description(); ?

    I use the Rich Text Tag plugin so that I can easily add in images and links, but when I make the echo call, it strips these out. Any ideas?

    Much thanks!

    July 28th, 2010
    • Amit Banerjee

      @matt: DO you use the echo codes from theme files or from WYSWYIG editor ?

      July 28th, 2010
  5. Matt Halfhill

    I use the echo codes from the template files.

    July 28th, 2010
  6. Ste

    I use tag desctipions on my site but since wordpress 3.0, the images (and other html) are stripped out. Any idea how to avoid this?

    September 2nd, 2010
    • Amit Banerjee

      @Ste: Can you provide more information on how exactly you are using the tag description in your WordPress theme ?

      September 2nd, 2010
  7. isimsiz

    i’ve been searching for this codes about 20 days. thanks for writing it here, my problem is solved.

    this code is not working on my theme. but your codes are working.

    ccc emeğe saygı ccc

    November 25th, 2010
  8. isimsiz

    i paste php echo category_description( $category ) ;

    code @ 1 comment before but it’s not shown.

    you code is working perfect

    November 25th, 2010
  9. Amir

    Hi Amit,
    Do you know a good theme that is pre-designed to show category description?
    Thanks,
    Amir

    December 9th, 2010
  10. Dave

    Hi,
    I need the tag description with its formatting. I am unable to have formatting since I am using Echo ().
    I have added a class before it as you mentioned but in vain.
    Please advise.
    Right now all my text is displayed in a single line without any new lines or other formatting.

    Please help!

    -Dave

    March 25th, 2011
  11. Dave

    hey I got it..
    I had to use a combination of a couple of functions for tags and get the description.

    Thanks :-)

    -Dave

    March 25th, 2011
  12. Ankur

    I have the Following Code and i am not able to get tag description to work..cat description did worked please help

    News About ‘’

    what code i need to change

    April 29th, 2011
  13. yoga

    “put the following code before in your WordPress theme” means which page ? archive.php ? or index.php?

    June 27th, 2011
  14. John

    Hi guys,

    Is there a plugin that switches this function in? Why do I need to edit php files – I am not a programmer. By default this category desription is shown – I do not see the point why it is not active. It would be important for seo… Any ideas for a plugin that lets category desription appear on the category page? Would help me a lot… Thanks guys!

    August 31st, 2011

Add Your Comment

All Comments are Moderated.

YOUR COMMENT

About This Site

Ampercent is a technology blog on computer tutorials, software guides, how to tricks and web tools. The blog is updated daily and written by two computer science students from India. Read More »

Tip Us »

Have a great tip which you want to share with fellow readers? Send in your ideas to tips@ampercent.com