Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add Category Descriptions to wp_nav_menu in WP 3.0 WordPress


I want to add category 'descriptions' to my main navigation (list categories) for a theme I am working on.

I am building this theme on WordPress 3.0, and would like to utilize the wp_nav_menu functionality, but cant seem to get it to display the category description as well.

The end goal is to do something like this -

Using the new menu navigation tool in wp 3 and have it display my categories, but also have it display each category description. I already have everything worked out except getting it to display the category descriptions.

Here is my current html structure for this area:

[[LINK href=""]]View Code[[/LINK]]

Answers (3)


Utkarsh Kukreti answers:

I was going to publish a similar tutorial in my site in a few days. Here's the modified code of it, to insert description inside em

add_filter('walker_nav_menu_start_el', 'description_in_nav_el', 10, 4);
function description_in_nav_el($item_output, $item, $depth, $args)
return preg_replace('/(<a .*?>)/', '$1' . "<em>{$item->post_content}</em>", $item_output);

Will produce

<a href="#"><em>The Description</em>A Category</a>

Aaron comments:

For me this did not wrap the description in em tags. Also can it flip-flop the category name and the description, so that the category name comes first, and then the category description with the category description wrapped in em tags?


Utkarsh Kukreti comments:


Aaron comments:

Looks good, except it does not close out the a link tag. it outputs this to the screen /a>

It's missing the '<' before the closing a link tag

Utkarsh Kukreti comments:


Oleg Butuzov answers:

can i help you? you want to show the category description? or you want to show the description of the nav_menu witch is relates to the category?

Aaron comments:

Yes to display the category descriptions.

Oleg Butuzov comments:

that's no sence. in this case you will need to amke twice more db queries for each of the menu can duplicate the the category description inside to the navigation menu. if thats ok for you i can make a custom filter for your menu.


Svilen Popov answers:

Try this
<?php echo category_description(5); ?>
where 5 is the cat ID.