How to Display Category Description in WordPress

We all know how important it is to categorize your blog posts. It helps your users to find the related content on your website. Categories provide a simple solution for grouping similar articles together. And if used correctly, categories can even help you with the SEO results too.

Along with the categories on your website, it is extremely crucial to display category description in WordPress as well. To display category description in WordPress is to give users a satisfying browsing experience and give more information about the categories. There should be a separate description for each category on your website. It should be a text that best describes the topics to be included in a particular category.

So, today, we are going to show you how to add and display category description in WordPress.

How to Add Category Description on WordPress

WordPress gives you the power to add categories while writing a new post. However, that only allows you to rename the category, not add the category description. That is why most of the bloggers miss the opportunity to add descriptions to their categories.

First of all, go to Posts > Categories from your dashboard. This will take you to a page where all the categories of your website will be displayed.

If you’re creating a new category, you will find separate fields for providing the title, slug, and the description.

Categories

Now, to add the descriptions to the existing categories, click on the “Edit” on the category, provide the description and then click on the “Update” button when you’re done. You have now successfully added category description. You can use this process to add descriptions to all of your categories.

Editing category description.

Having said that, now let’s move forward to displaying your category description.

Display Category Description on Category Archive Page

Some of the WordPress themes automatically display the category descriptions on the category archive pages. To check if your theme supports the feature, open a category archive page and see if the description you added is displayed or no.

Category - People

However, if your theme doesn’t automatically display category description on archive pages, then you need to edit your theme files.

Connect to your WordPress site using an FTP client and then go to /wp-content/themes/your-current-theme/ folder.

Now, you will need to locate and edit category.php file. If your theme doesn’t have category.php file, then you will need to edit archive.php file.

Copy and paste the following code where you would like the category description to be displayed.

<?php
the_archive_description( '<div class="taxonomy-description">', '</div>' ); 
?> 

Save your changes and upload the file back to your website. You can now visit the category archive page to see the category description in action.

Display Category Description in WordPress Theme

Most WordPress themes will only show the category description on the category archive page. However, you can display category description in other places of your website too by using the category_description template tag:

<?php echo category_description(3); ?>

Makes sure you replace 3 with your own category ID.

If you want to display category description inside a single post, then you can use the following code:

$catID = get_the_category();
echo category_description ( $catID[0] ); 

The code will simply get all categories for the current post and then output the category description of the first category.

If you want to list all your WordPress categories with their respective descriptions, then you can add the following code in your theme’s functions.php file.

function wpb_catlist_desc() {
$sring = '<ul>';
$catlist = get_terms( 'category' );
if ( ! empty( $catlist ) ) {
  foreach ( $catlist as $key => $item ) {
    $string .= '<li>'. $item->name . '<br />';
    $string .= ',em>'. $item->description . '</em> </li>';
  }
}
$string .= '</ul>';

return $string;
}
add_shortcode('wpb_categories', 'wpb_catlist_desc'); 

The code will create a shortcode that will display all your categories and their descriptions in a plain list. You can now use [wpb_categories] in your posts and pages. To use this shortcode inside a text widget, you will need to enable shortcodes for widgets.

That is all that’s there to it. We hope this post helped you to display category description in WordPress properly. Which method did u like the most? Let us know in the comments.

 

Reference: WP Beginner, WP Dean

Leave a Reply

Your email address will not be published. Required fields are marked *