Adding HTML and Shortcode support to WordPress Category Descriptions

This is a guest article by Dan Harrison, who’s the director and chief developer for WordPress Doctors. Dan is also an experienced affiliate marketeer, focusing on eco and gadget niches.

Many of us spend a lot of time on our affiliate sites making them damn useful for our website visitors. That includes adding plenty of relevant and useful content. How many of you are adding descriptions to all of your categories? I expect quite a few of you are already doing it.

Are you frustrated by WordPress’s default behaviour of not permitting HTML in Category Descriptions? Do you want to add bold, images, perhaps even video to your categories? Well this article shows you how to fix that, plus another little trick for supporting WordPress shortcodes.

Adding HTML in Category Descriptions

This is a very simple fix, allowing HTML in category descriptions just requires you to add the following code to functions.php for your current theme:

$filters = array('pre_term_description', 

foreach ( $filters as $filter ) {
	remove_filter($filter, 'wp_filter_kses');
remove_filter('term_description', 'wp_kses_data');

That code basically tells WordPress not to strip out HTML when saving a category description. So now, HTML will work in your current theme.

HTML Categories description editing

HTML Categories description rendered

Adding Category Descriptions to your WordPress Theme

If you don’t already have category descriptions in your theme, then add the following code to your theme’s category.php. If you don’t have a functions.php file, then copy index.php to category.php, and make some tweaks.

$category_description = category_description();
if (!empty( $category_description)) {
	echo '<div class="category_description">' 
	      . $category_description . 

Adding Shortcode Support to Category Descriptions

If you don’t know what a WordPress shortcode is, it’s basically a word inside square brackets that looks a little like HTML, e.g. [example_shortcode /]. In WordPress it’s the best way to insert ‘stuff’ into the main content of a page by a plugin or theme. e.g. this might include inserting YouTube videos without having to insert the nasty embed code.

If you know what they are, then you might appreciate being able to add shortcodes to category descriptions. To add shortcode support, you just need to tweak the code for showing descriptions to the following, using WordPress’ do_shortcode() function:

$category_description = category_description();
if (!empty( $category_description)) {
	echo '<div class="category_description">' 
	      . do_shortcode($category_description) . 

HTML Categories with Shortcode editing

HTML Categories with Shortcode rendered


So there you go, some simple code that you can copy’n’paste into your WordPress theme to allow you to create pretty category descriptions. I hope you found that useful!

Please do post your examples in the comments below, we’d love to see what you’ve done with yours. Please only post 1 or 2 links in your comment though, so that the spam filter doesn’t automatically remove your comment.

Adding Meta info to WordPress Categories

Yesterday I was trying to figure out, find a plugin, that would enable me to add meta information to wordpress categories, I use All-in-one-seo so wanted something to work along side this and not have to install another SEO plugin, this took longer than I thought it would as I was messing about trying to get Category Meta Plugin to work without success and there was no clear information or successful installs from my Google search to help me with this.

Then I came across Category SEO Meta Tags, it was exactly what I had been looking for and was so simple to install, best of all it works perfectly, so hopefully this post will help anyone else in the same situation and save them time trying to find the right plugin.

Installing multiple WordPress to one database

If, like me, you have a restriction on the amount of SQL databases you can have on your hosting then this is a little tip that I had trouble finding out when I wanted to create more WordPress sites.

I have a restriction of 15 databases with my 1&1 hosting account, I started to look around for a new host but didn’t really fancy moving all my domains as it would be a bit of a nightmare, so this is the solution.

In your wp-config.php file you can change the prefix of the tables that are created, the default is ‘wp_’ so you can change this to anything else, for example ‘ps_’ or ‘sq_’, this will enable multiple installs of wordpress on one database.