08
Adding a biography to your Wordpress posts
On news and article sites you often see a little biography about the author, just before the comment section. I wanted to have this for a Wordpress site while keeping it as simple as possible for the author.
The Biographical Info field in the author’s profile would seem the logical choice but it only accepts plain text, whereas I wanted links as well. So instead, here is a quick way to display the author’s biography using a Wordpress Custom Field.
In your theme, open up single.php and after <div class="entry">...</div>, add the following (sorry about the borked layout):
<?php if (get_post_meta($post->ID, 'Bio', true) ): // Only show if Bio key is set ?>
<div class="author">
<span class="gravatar">
<?php echo get_avatar( get_the_author_email(), '40' ); // Display the author's gravatar at 40x40px ?>
</span>
<div class="bio">
<h3>Author: <?php the_author_nickname(); // Can use the_author() instead ?></h3>
<p><?php echo get_post_meta($post->ID, 'Bio', true); // Show Bio ?></p>
</div>
</div>
<?php endif; ?>
Add some CSS to the box to float the author’s picture and tie in with your blog theme:
<style>
.author {margin-top:10px;padding:10px;border:1px solid #EECF9F;background-color:#FDF4E5;}
.author h3 {color:#513810;margin-left:6px;}
.gravatar{margin-right:10px;float:left;}
.bio {margin-left:45px;}
</style>
Now when you’re writing a post, add a new custom field with the Name Bio and type a little bit about the author in the Value field (the author box will only show on the post if there is a Bio custom field). Publish or update the post and that’s it! Below your post you should now have something like:

Extra:
1. In your post template, you could change the line Posted by author to an anchor link for the bio box instead i.e. Posted by <a href="#author">author</a>.
2. If you don’t want to have multiple registered Wordpress users but still want to have different contributing authors with a biography for each, try combining with this function. It allows you to define a guest author as a Custom Field.
Tags: biography, code, custom field, wordpress






