WordPress “About The Author” Without Plugins
by Cosmo Catalano
While I love that WordPress has a huge developer community, a lot of plug-ins are overkill. WP does a great job of packaging CMS features into its core functions, meaning that a ton of awesome content is available, usually in a single line of code.
Let’s take the “about the author” boxes, popular on professional and non-anonymous blogs. A default install of WordPress 3.x already has a system for keeping track of user data (it’s under “Users” in the left-hand column on the Dashboard), and a function (
get_the_author_meta) to call up that data at any point in any template.
Combine that with WP’s built-in Gravatar support (
get_avatar; you do have a Gravatar set up for all your email addresses, correct?) and you’ve got the photo and bio information you need in two lines of code.
For formatting, we can turn to what might be my favorite WordPress feature—the ability to put raw PHP into a template. The
nl2br() function turns your user-supplied line breaks into HTML
<br/> tags to prevent the dreaded Wall of Text. Wrap that all up in a few easy-to-style
<div>s and you’re good to go:
<div id="author-profile"> <h4>About the Author</h4> <div id="author-bio"> <p> <?php $text = nl2br(get_the_author_meta('description')); echo $text; ?> </p> </div> <div id="author-avatar"> <?php $link = get_the_author_meta('user_url'); $email = get_the_author_meta('email'); $image = get_avatar($email, 200); echo '<a href="'.$link.'">'.$image.'</a>'; ?> </div> </div>
You can paste that into most WordPress template files (I prefer
footer.php, as seen below) and voila—about the author, no plugins needed.
I get that there are good theories behind the use of WP plugins; users with no technical background can add functionality to their websites. From a best-practices standpoint, plugins keep features independent of what theme you’re using.
But in the real word, WordPress places a pretty serious load on most cheap, shared hosting accounts. Keeping down the number of plugins piling onto your WP install will keep your site snappy, your search rank high, and your users happy.