Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /home/dh_432dct/themedev.thepixelpixie/wp-c0nt3nt/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 22

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /home/dh_432dct/themedev.thepixelpixie/wp-c0nt3nt/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 28

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home/dh_432dct/themedev.thepixelpixie/wp-c0nt3nt/plugins/gravityforms/includes/assets/class-gf-asset-processor.php on line 59
Enabling HTML in your category & taxonomy descriptions | Pixie Nerd Theme
Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /home/dh_432dct/themedev.thepixelpixie/wp-c0nt3nt/plugins/wordpress-seo/src/generators/schema-generator.php on line 185
Go to the top

Enabling HTML in your category & taxonomy descriptions


Warning: Trying to access array offset on value of type bool in /home/dh_432dct/themedev.thepixelpixie/wp-c0nt3nt/themes/darwin/single.php on line 246

You may not be aware of it, because most themes don’t make use of it, but did you know that you can include your category descriptions and images in themes? Well, you can. AND, not only that, you can allow html tags within those category/taxonomy descriptions!

First, let’s ensure that your theme can use this feature (this is assuming you’re using a fully custom or child theme. If not, you risk these changes being overwritten with any future updates from the theme developer)

Setting up your theme to allow for category/taxonomy descriptions

Open your category.php file within your theme files. Now choose where you’d like your category description to appear (a common place is right below the category title tag itself):

<h1 class="title"><?php printf( __( 'Category Archives: %s', 'appthemes' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>

<?php
// this part is new
$cat_desc = category_description();
if ( ! empty( $cat_desc ) ) {
    echo apply_filters( 'category_archive_meta', '<div class="cat-desc">' . $cat_desc . '</div>' );
}
?>

Want the same thing for a custom taxonomy? Just replace category_description() with term_description(). And if you’re really wanting to get fancy, use tag_description().

See, here’s the thing: I wish more people were using these category, term and tag descriptions in their themes. Not only are they simply a good way to provide extra descriptive content for each category, term and tag, but those extra descriptions are also a fantastic way to incorporate more of your keywords and phrases to help with your Search Engine Optimization (SEO) efforts. So get ON that!

Now, what you may end up noticing is that when/if you try to enter any html tags into those descriptions, they will often disappear once you’ve saved it (sometimes simple tags for bold and italic and the like will get saved, but most anything else will disappear).

Enabling HTML in those descriptions

You can enable html in those category/term/tag descriptions though.

In your themes functions.php file, enter the following lines:

// allow html in category and taxonomy descriptions
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'pre_link_description', 'wp_filter_kses' );
remove_filter( 'pre_link_notes', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );

IMPORTANT NOTE: Note that this code removes the native security features that WordPress applies to those fields. If you have quite a few authors with access to your site, or run a large multi-site blog, this could end up creating a security risk since malicious code could also be inserted. Large sites with multiple authors will probably want to forgo allowing html in those description areas. If you’re a normal-sized site, with only a handful of authors though, you should have no issues. I trust that you already have other security measures in place anyhow, such as iThemes Security or similar (there are both free and pro versions available).