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)
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).
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).