Display Category Descriptions, Tag Descriptions and Author Bios in Wordpress wordpress 120x120Most 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>");
endif;

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 to see which files are used for what.

  • Mjh76016

    Jim, this is a total newb question. i want to add desriptions for categories, but have no idea about code, php, or anything. can you tell me where to put the code. from what i have seen online i am supposed to put this in either category.php or archives.php. i dont seem to have a category.php. i cannot begin to tell you where it should go in archives.php. i have no idea what a loop is. i really just want an intro for categories. any help would be appreciated.

    • http://www.jimcode.org Jim Rowe

      Hi, I assume you mean for a WordPress site? The files in your template are mostly optional – so index.php would be used for everything as a backup. You should be able to create a template for categories, or even a different template for each category – take a look at this… http://codex.wordpress.org/Template_Hierarchy

      Alternatively some themes probably have this built in, since you can add descriptions to cateories and tags in the wordpress admin, so if you are not happy writing code for all of this you may want to look for a new template.

      • Mjh76016

        sorry, yes it is wordpress. thanks for the info.