Allow HTML in Taxonomy Descriptions

Setup taxonomy descriptions to include html

Some of the most underutilized fields in WordPress are the category, tag, and taxonomy description fields. These fields can actually be displayed on the front-end and used to really build out your category and tag pages.

The problem is category description fields (or any taxonomy description fields) are limited to just basic html markup (i.e. a href, strong, etc) but what if you want to also include other html?

Here’s a nifty block of code that allows you to do just that. It removes the sanitize filters from any taxonomy description field (i.e. blog category, custom taxonomy).

Add the following code to your functions.php file and then add some html to your category, tag, or taxonomy description fields and then view them on your site (you’ll need to have the correct php code in your theme templates in order for it to show up).

Code to Remove HTML Filters

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

Now the code is setup to easily pass in other items you’d like to remove the filters from. For example, if you also want to add html to your link description and user profile description fields, just add these two items to the $filters array like so:

Remove Filter From Additional Fields

$filters = array( 'pre_term_description', 'pre_link_description', 'pre_user_description' );

Here’s the code you’ll want to have in your theme template file (i.e. category.php) in order to display the new descriptions. Some themes may not already have this in there which means it won’t show up.

Code to Display Description on Category Page

$category_description = category_description();
if ( ! empty( $category_description ) )
    echo apply_filters( 'category_archive_meta', '<div class="category-desc">' . $category_description . '</div>' );

To display the description for other taxonomy pages, you’ll need this code added to your taxonomy-[TAXONOMY_NAME].php template.

Code to Display Description on Custom Taxonomy Page

$term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
echo '<h1>' . esc_html( $term->name; ) . '</h1>';
echo '<p class="desc">' . esc_html( $term->description; ) . '</p>';

That’s it. Now you can build out your boring category, tag, and custom taxonomy pages with rich html descriptions.

Here's the final result on the front-end

Here’s the final result. The image path was incorrect which is why the image isn’t showing up correctly.

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 4.5 - 6 votes

Written by: on July 15, 2011. Last modified: July 15, 2011

Popular Marketplace Items

  • Authorize.Net Thumbnail


    Easily start accepting online payments via credit card and e-check.
  • screenshot


    A conversion focused responsive Clipper child theme with premium features.
  • balanced-payments-plugin-sm

    Balanced Payments

    Accept credit cards and setup escrow payments.
  • classipress-fortumosms-gateway

    Fortumo SMS payment gateway

    Fortumo sms payment gateway for ClassiPress
  • autoauto-thumbnail

    AutoResponder AutoRegistration

    Automatically integrates WordPress registration with major autoresponders.
  • 2Checkout Payment Gateway Plugin


    Accept up to eight payment methods, fifteen languages, & twenty six currencies.
  • at_autosuggest_taskerr_thumb

    AutoSuggest – Taskerr

    Automatically suggests services as the user types.
  • GeoReg thumbnail


    Captures detailed geographic info with new user registrations.
  • classpress tabber


    Show specific custom fields as tabs on an ad detail page.
  • wp-smart-export-final

    WP Smart Export

    A highly customizable WordPress data exporter plugin.
  • StarStruck WordPress Plugin Thumbnail


    A fast, lightweight, and elegant star rating system for comments, pages, & posts.
  • woo_marine_thumb


    A clean, modernĀ and fully responsive marine-based goods WooCommerce Theme.
  • adposter-blocker-thumbnail

    AdPoster Blocker

    A simple but powerful plugin that blocks spammy new user regs and/or ads/jobs/posts.
  • thumnail

    Category Icons

    Add icons to your ClassiPress categories
  • daddy-likes-190x130

    Daddy Like

    A fast, lightweight, and elegant "like" system for comments, pages, posts, & activities.
  • pcp-featured

    Price Comparer

    Jump start your Price Comparision site with products from Amazon, Commission Junction, and LinkShare.
  • Custom Greeting

    Custom Greeting

    Easily replace the default WordPress greeting.
  • stripe-plugin


    Process credit cards safely and securely on your AppThemes website.
  • featured

    QR Codes Widget

    Add a widget with QR codes to your AppThemes site.
  • AppThemes Coupon Plugin

    AppThemes Coupons

    An easy way to start offering coupons and promotions to your customers.
  • woo_goodstore_thumb


    A clean, modernĀ and fully responsive WooCommerce Fashion Theme.
  • critic-icon-2


    A professional review and rating system for WordPress.