More Exposure for your Post Author

The last blog post about the Google Panda update was written by Michele, a new author for the Web Development Blog. Because she is the first author beside me, we thought it’s important to provide some information about Michele below each blog post. We explain in this “beginner” WordPress tutorial how-to place the post author’s biography below the blog post and how-to place the same information at the top of the author’s archive page.

WordPress Tutorial: Show the post author’s information

The core functionality of WordPress makes it possible to enter some information about the post author and there is also a standard archive page for each author. In this tutorial we like to show the (full) name, the biography or description and sometimes the URL of from the author below a post and the author’s archive page.

How-to obtain the author’s details in WordPress

Inside the WordPress codex we found the very useful function called “get_the_author_meta()”. With this function it’s possible to access the author’s meta data like:

$bio = get_the_author_meta('description');
$fullname = get_the_author_meta('display_name');
$url = get_the_author_meta('user_url');

Create an post author box for each blog post

Using these variables it’s possible to create a box which shows the information about the author. Open the WordPress theme file called “single.php” and place this code right below the part with “the_content(…”.

echo '
<p id="authorBio">
	<strong>About <a href="'.$url.' target="_blank">'.$fullname.'</a></strong><br />
	'.$bio.'
</p>';

This code snippet will show an extra paragraph at the bottom of each post including the name and the author’s website URL (of course the profile data need to be filled first).

Because the bio/description field filters most of the HTML tags we use a small workaround. Inside the bio/description fields it’s possible to use “normal” line breaks:

About the author

While WordPress will store the line breaks in our database, they will not show up in our WordPress theme. We need to use the PHP function “nl2br()” instead.

Modify the WordPress post author archive page

We mentioned before the standard author archive page which shows the posts written by an author. How about to place the author’s information on that archive page too?

First we need to identify the author on that archive page and than we need to receive the author’s data. Open the file archive.php and add the following code (there should be some code for the different types of archives, place it inside the IF clause for authors):

$aid = get_user_by('slug', get_query_var('author_name'));

Note that “$aid” is an object, add the information on different spots in your archive theme like:

echo 'Author Archive for "'.$aid->display_name.'"';

or the description like:

if (!empty($aid)) {
	echo '
	<p>'.nl2br($aid->description).'</p>';
}

Create independent archive pages for your authors

Using the WordPress “rules” on how different themes are “called”, it’s possible to create unique archive pages for each post author.

For example, copy your “archive.php” file and save it under the name “author-admin.php” or “author-10.php where “admin” is the authors “nicename” and “10” is the author’s user ID. Inside this new theme file it’s possible to create custom content for the author page. We did the same for our WordPress categories before, using unique content for the author page will help your on-site SEO as well.

If you have any questions please post your comment below, we’re glad to help.

Published in: WordPress Development

3 Comments

  1. This is such a great post. I always wondering how can I make the guest post on my website have this box containing the author’s short biography. And now I read it from your blog. Thank you, I will implement this immediately and look at the result.

Comments are closed.