How to Display Category Descriptions in WordPress

How to Display Category Description in WordPress main image

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 descriptions in WordPress as well. To display category descriptions in WordPress gives users a satisfying browsing experience and gives 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 descriptions in WordPress.


Category Descriptions in 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 bloggers miss the opportunity to add descriptions to their categories.

From your WordPress Dashboard, go to Post Category page from Dashboard => Posts => Categories. This will take you to a page where all the categories of your website will be displayed.

From here you can also create a new category. For this, you need to fill in Category Name, Slug, and Description and finally click on the “Add New Category” button.

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 a 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.


Hot to Display Category Description on Category Archive Page?


Some of the WordPress themes automatically display the category descriptions on the category archive page. To check if your theme supports the feature, open a category archive page and see if the description you added is displayed or not. Our WordPress theme “DevotePress” supports it automatically. You can check the example here in the People category.

Category Description Preview

There might be some theme that doesn’t display the category description on the archive pages, then you need to edit that 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 the category.php file. If your theme doesn’t have a category.php file, then you will need to edit the 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>' ); 
?> 

Source: WordPress.org

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 descriptions in other places of your website too by using the category_description template tag:

<?php echo category_description(3); ?>

Source: WordPress.org

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, you can add the following code to your theme’s functions.php file.

function yourthemeslug_category_list_description() {
$displaycategory = '<ul>';
$categories = get_terms( 'category', 'orderby=count&hide_empty=0' );
if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) {
  foreach ( $categories as $key => $item ) {
    $displaycategory .= '<li><strong>'. $item->name . '</strong><br />'. $item->description . '</li>';
  }
}
$displaycategory .= '</ul>';

return $displaycategory;
}
add_shortcode('yourthemeslug_categories', 'yourthemeslug_category_list_description'); 

The code will create a shortcode that displays all your categories and descriptions. Since we have created the shortcode, you can use [yourthemeslug_categories] in your posts and pages where to want to display. You can also use this shortcode in the “Text Widget” to display in your widget areas like Sidebar and Footer widgets.

That is all you need to do. We hope this post helped you to display category descriptions in WordPress properly. Which method did u like the most? Let us know in the comments.

Source: WP Beginner

Leave a Reply

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