i asked this on SO but got no where. i will try asking here.

this works fine in category.php <?php echo category_description(the_category_id()); ?>

but it does not work in single.php, just the category id shows up not the description.

any ideas, how to get this done?

thanks in advance


in category: <?php echo strip_tags(category_description(4)); ?>

in single <?php echo category_description(the_category_id()); ?> cat id = 4

i know i'm not striping the tags..for single

i'm just trying to display the cat desc when in the single post page.

  • Not surprising you'd get no help for WordPress at SO; they are not WordPress enthusiasts, we are. :) Can you please provide some context for your question? Can you show the code from category.php where you are displaying the code where it works and where in single.php you want the code to work? Where you want to use it matters a bit. Commented Dec 26, 2010 at 3:27
  • @Mike thanks, actually in both cases(single + cat) I am calling the function outside the loop..right before the loop starts... i edited the q a bit.
    – andrewk
    Commented Dec 26, 2010 at 3:57

1 Answer 1


Try the code that follows the screenshot:

Displaying WordPress Category Description
(source: mikeschinkel.com)

  $categories = get_the_category();
  foreach($categories as $key => $category) {
    $url = get_term_link((int)$category->term_id,'category');
    $categories[$key] =
      "<dt><a href=\"{$url}\">{$category->name}</a></dt>" .
  echo "<dl>\n" . implode("\n",$categories) . "\n</dl>";

Also, <?php echo category_description(the_category_id()); ?> doesn't do what you think it does. What follows will work on your category pages because it assumes the category ID for the category page:

<?php echo category_description(); ?>

FYI, the_category_id() will echo the value of the current category ID, it doesn't actually pass anything to category_description() is looks like was your assumption. Besides, the_category_ID() is deprecated so you wouldn't want to use it anyway. By the way, I'll bet you are seeing an errant number being displayed just before the category description is displayed?

  • @Mike you rock. thanks a bunch. all of your answers are so straightforward. You are bettering the world. thanks man.
    – andrewk
    Commented Dec 26, 2010 at 5:04
  • @andrewk - You are welcome. :) Happy Holidays. Commented Dec 26, 2010 at 7:52
  • hey @mike take a look at this.. stackoverflow.com/questions/4529618/… it seems simple.I appreciate both.
    – andrewk
    Commented Dec 26, 2010 at 21:15
  • @andrewk - Yes, his is simple but it does less. His only gets the first category and does not hyperlink it. Mine gets all categories assigned to a post and formats them nicely including with hyperlinks. I usually try to anticipate the things you are going to want and need and thus give more complete answers. So his is an engine. Mine is a complete car that includes an engine. :) Hope this helped. Commented Dec 27, 2010 at 19:02
  • As always, I have learned a lot from your answer - thanks Mike.
    – davemac
    Commented Feb 28, 2011 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.