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?

6 comments on “How to Add HTML, Scripts in WordPress Category Descriptions

  1. Retweet Exchange says:

    I have done this before and I hope this helps many who were wondering how it’s done. Thanks for sharing

  2. Bobby says:

    Thanks for share this article.
    BTW, can you put some picture that show this code result. So, we can imagine to work with it.


  3. fazal mayar says:

    thanks for this trick, I am that good with coding.

  4. travel spots says:

    I have been searching for this for long time and finally got it here. thanks for useful tips.

  5. anotherbreed says:

    Thank you, this worked like a charm!

Leave a Reply

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