How to Display Category Description in WordPress Easily
“How to display categories description in WordPress” has got to be one of the rarest WordPress queries.
Table of Content
Categories are a common yet overlooked WordPress feature. While they have been around for a long time, many users still do not use them correctly.
Why Display Category Description in WordPress
An important reason why users overlook WordPress display categories when drafting their blogs is the simple fact that generally, no description appears with the categories. Thus, users often skip this important step.
Categories allow you to sort and find content on your website. They are also beneficial for your website’s SEO. In this article, I will take you through the process to display category description in WordPress.
Display Category Descriptions to the Posts
The process of adding category descriptions in WordPress is easy. Start by going to Posts >> Categories.
Now, go to the theme’s folder and open archive.php. Add the following code to the file:
1 2 3 |
<?php the_archive_description( '<div class="taxonomy-description">', '</div>' ); ?> |
Now, when you wish to display WordPress category description, you just need to use the following code snippet:
1 |
<?php echo category_description( $category_id ); ?> |
In order to show the list of categories, along with their description, add the following code snippet to functions.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
add_shortcode('wpblog_cat', 'wpblog_cat_des'); add_filter('widget_text', 'do_shortcode'); function wpblog_cat_des() { $demo = '<ul>'; $listcat = get_terms( 'category' ); if ( ! empty( $listcat ) ) { foreach ( $listcat as $key => $item ) { $demo .= '<li>'. $item->description . '</li>'; } } $demo .= '</ul>'; return $demo; } |
The above code snippet will generate the following shortcode:
[wpblog_cat]
Shortcode Placement
The shortcode is used to display category description. To use it, place the shortcode in a text widget and then place the widget at the location where you wish to display the category description in WordPress.
Conclusion
Displaying WordPress category descriptions is a great way to ensure that the users choose correct categories for their posts. This article describes a simple way to display WordPress category description. If you need help with the idea, leave a comment and I will get back to you.
Create Faster WordPress Websites!
Free eBook on WordPress Performance right in your inbox.