How to Add HTML, Scripts in WordPress Category Descriptions

How can you add HTML code and scripts in WordPress category descriptions? WordPress category description is a text box which will by default strip any tags, scripts  or html code if you attempt to save it. But adding code for images, links, javascripts can enhance the usability, functionality and search engine rankings of your category pages.

Block WordPress Filters

Normally WordPress has powerful filters which block and strip code, so if you disable the filter, you can add whatever you like in the input forms. I followed this discussion and found this useful tip.

In the theme editor, open your themes functions.php file and add this code before the closing php closing tag ?>

$filters = array('term_description' , 'category_description' , 'pre_term_description');
foreach ( $filters as $filter ) {
remove_filter($filter, 'wptexturize');
remove_filter($filter, 'convert_chars');
remove_filter($filter, 'wpautop');
remove_filter($filter, 'wp_filter_kses');
remove_filter($filter, 'strip_tags');

Warning: Any wrong code entry to the functions.php file can take your blog down and block wp access. So fiddle with it only if you know what you are doing. If something goes wrong, edit the file to original via ftp, and all will be well.

Add Category Description Theme Support

Now you need to enable the category description code in your theme (which is usually absent). So in your theme editor open archive.php (which displays tags and categories archives) and add the following code after the Category / Tag headline.

<?php echo category_description(); ?>

Add HTML to Category Description

Now you can add any html code and scripts to description fields of categories and tags.

Wordpress category html description

Make useful category and tags descriptions and see the rising search engine ranking of these pages. Do you like this design + SEO tip?

Share with friends

About the Author: P Chandra is editor of QOT, one of India's earliest tech bloggers since 2004. A tech enthusiast with expertise in coding, WordPress, web tools, SEO and DIY hacks.