Support » Fixing WordPress » Category description strips html tags

  • I want to be able to use my own HTML in the category description, allowing me to add lists, or break paragraphs where I want, while retaining valid (x)HTML.

    Eventually, I’ll use the description to display it on each category page.

    Unfortunately, WP seems to over-write all tags I manually put in there. Most annoying.

    Any ideas on how to solve? I’ve sifted through codex and forum and google, I can’t seem to find a solution to this.


Viewing 15 replies - 1 through 15 (of 15 total)
  • What sort of HTML are we talking about? I use p, strong, and em tags in my category descriptions regularly without problems.

    p were stripped out.

    ol, ul and li were stripped out.

    a href was left intact.

    blockquote was stripped out.

    I also would love to be able to include html and even php code in category description.

    In wp-includes/default-filters.php, comment out add_filter($filter, 'wp_filter_kses');, like shown below (line 29).

    $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
    foreach ( $filters as $filter ) {
          //add_filter($filter, 'wp_filter_kses');

    A better option might be to write a plugin to do it, but I can’t help you there — yet.


    OK, so that was easy…

    Copy the text below into a text file and save it as html-in-category-descriptions.php in your plugins directory.

    Arno Esterhuizen

      Plugin Name: HTML in Category Descriptions
      Version: 1.0
      Plugin URI:
      Description: Allows you to add HTML code in category descriptions
      Author: Arno Esterhuizen
      Author URI: ****
    $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
    foreach ( $filters as $filter ) {
        remove_filter($filter, 'wp_filter_kses');

    Thank you *so* much, arno. I actually just pasted your code (including copyright comments šŸ˜‰ ) into my existing “functions.php” inside my template directory, and it works like that too.
    Just what I needed!

    I’ve got the same problem, I want to find some plugin that will keep the post content in category page with part of html, not part of raw text, expecially I want to keep some pics in the post.

    I figured out how to hack the default-filters.php file (referred to above) for version 2.6, which has changed what they call category_description. It’s now called ‘term_description’. I did a hack and slash and commented out anything filtering the term description including the below.

    // Kses only for textarea saves
    $filters = array(/*'pre_term_description',*/ 'pre_link_description', 'pre_link_notes', 'pre_user_description');
    foreach ( $filters as $filter ) {
    	add_filter($filter, 'wp_filter_kses');

    and this bit:

    // Format text area for display.
    //$filters = array('term_description');
    //foreach ( $filters as $filter ) {
    //	add_filter($filter, 'wptexturize');
    //	add_filter($filter, 'convert_chars');
    //	add_filter($filter, 'wpautop');

    Worked for me.
    Sophia Kelly

    The problem with this is that when you update WordPress, your hack will be overwritten with the newest default-filters.php file.

    Using a plugin or a functions.php solution is update-proof. Most of the time šŸ™‚



    This broke with 2.6.1 for me, i had to add
    pre_term_description, just add the following block to functions.php in your theme.

    $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’);

    html comments are still filtered out. any idea how to stop this? – i’d like to make my own <!–more–> function for descriptions…

    arno_esterhuizen solution is preferable. As already said, hacking the core is not a good idea, if you can do it with a plugin. I tried this plugin with 2.7 and it works perfectly. Thanks arno_esterhuizen!

    OK, I have installed this plug-in and it works as expected, but there’s a problem. The Category Description is also used as the TITLE for the category navigation link, so there’s now HTML in the link!

    Is there a way to extend the plugin so it overrides what is return to the “wp_list_categories” call and strips out the HTML in that situation specifically?

    Thanks to arno_esterhuizen for a nice plug-in solution.


    Using arno_esterhuizen’s method in 2.7 and it works great.

    2 issues:

    1. echo rEd86’s point: mousover the category in navigation and the whole description, including html markup, pops up.

    2. I want to conditionally display the description if it exists. I’ve tried this:
    if (category_description()) { echo category_description(); }
    but it doesn’t work. If category description is empty, it’s still echos a line break.

    use wp_list_categories(use_desc_for_title=0)

    Shalako: try adding a trim() like this: if (category_description()) { echo trim(category_description()); }

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Category description strips html tags’ is closed to new replies.