Display Category Descriptions, Tag Descriptions and Author Bio’s in WordPress

May 6, 2011

WordPressMost WordPress templates don’t seem to support displaying the descriptions for categories, tags and the author bio’s. Here is a quick explanation of how you add that information into your WordPress admin and then how to change your templates to display it.

The main reason for wanting to do this is simply to provide a little extra supplementary information on lots of your blogs pages – but it may also have some benefit for SEO as well.

Category Description

This is the simplest of the lot, you have a description field when you add/edit a WordPress category description. Some themes may already display this field, but if yours doesn’t then the following code should help you out. The extra bit about apply filters is there to allow plugins and hooks to do their thing with the description as well but if you aren’t bothered about that then you can ignore it.

$categorydesc = category_description();
if ( ! empty( $categorydesc ) ) {
    echo apply_filters( 'archive_meta', '
<div class="archive-meta">' . $categorydesc . '</div>
' );

Tag Description

You can add or edit tag descriptions in the same way as category descriptions but your theme is much less likely to support displaying them. The following code is getting a bit more interesting and uses the wp_specialchars function and strip_tags to ensure the tag descriptions are safe, since you may want to allow users of your site to add them.

if ( is_tag() && tag_description() ) {
    echo "<div class=\"archive-meta\">";
    echo rtrim( wp_specialchars( strip_tags( tag_description() ), 1 ));
    echo "</div>";

Author Bio

Finally we come to the author bio which you, or your users, can edit on their profile page. The code uses the really handly nl2br function so that you can go on about yourself a bit longer and get line breaks between paragraphs.

if ( get_the_author_meta('description') ) :
    echo "<p>".nl2br(get_the_author_meta('description')."</p>");

Just a final note to say that this requires that your template uses different files for displaying author, category and tag archives. You might want to take a look at the WordPress [Template hierarchy][1] to see which files are used for what.

[1]: http://codex.wordpress.org/Template_Hierarchy#Visual_Overview