Display category description in WordPress theme

Display category description in WordPress theme

Should you ever need to display the category description in your WordPress theme, and it doesn’t show after you save the category, then you should modify the theme files so it can display it for you.

1. Edit the category.php file

Go to /wp-content/themes/your-theme-name/ and look for category.php file. If it doesn’t exist then look for archive.php file, and if that one doesn’t exist either then open the index.php file in your preferred text editor.

Insert the following code where you want the description to appear (mostly on top of the page):

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

2. Enable the HTML usage in category description

If you are using older version of WordPress for some reason and therefore you lack the option of using the HTML in category description, then open the functions.php file in text editor and paste the following code after the opening &lt;? php statement:

remove_filter('pre_term_description', 'wp_filter_kses');

Now you can insert whatever HTML you like in your description box.

Apendix

If you want to display the category description in other parts of your website, then you can also use the category_description template tag:

<?php echo category_description(category ID number); ?>

NOTE: Replace “category ID number” with your actual category ID number.

0 comments

Leave a Reply