
Using WordPress hooks, it can be very easy to modify WordPress variables to fit your needs. In this recipe, I’m going to show you how to use hooks to automatically insert the author bio after each post.

Using WordPress hooks, it can be very easy to modify WordPress variables to fit your needs. In this recipe, I’m going to show you how to use hooks to automatically insert the author bio after each post.
Open your functions.php file and paste the following code. That's all you have to do!
function get_author_bio ($content=''){
global $post;
$post_author_name=get_the_author_meta("display_name");
$post_author_description=get_the_author_meta("description");
$html="<div class='clearfix' id='about_author'>\n";
$html.="<img width='80' height='80' class='avatar' src='http://www.gravatar.com/avatar.php?gravatar_id=".md5(get_the_author_email()). "&default=".urlencode($GLOBALS['defaultgravatar'])."&size=80&r=PG' alt='PG'/>\n";
$html.="<div class='author_text'>\n";
$html.="<h4>Author: <span>".$post_author_name."</span></h4>\n";
$html.= $post_author_description."\n";
$html.="</div>\n";
$html.="<div class='clear'></div>\n";
$content .= $html;
return $content;
}
add_filter('the_content', 'get_author_bio');
Thanks to Lam Nguyen for this cool little trick!
29 Responses
Thanks for the mention and enjoying my post
thanks! i’ll give it a try
great post! usable for community site that have many authors
I might be missing the point slightly, but why do this over just editing the single.php file?
I wish you had a screenshot of this – direct example of this code… Oh, well, I have to check and pay particular attention to your other posts. You just might be using this… Okay will try this tip. I have occasional guest writers in my blog so this is a great way to jazz up the author’s bio at the end of the post. Thanks!
It turns out I’m working on an article on this… scooped!
That’s ok, I’ll remix this one (with full credit all around), and add extra styling, etc. Good motivation to get this out of my Drafts queue.
Thanks again for a great tip!
Thanks for the snippet. It is so simple but can have a great impact on your blog especially if it is has multiple authors.
Thanks again as always.
@Alex: You can simply just edit single.php file; however, your Bio box will not display right after the post content because some plugins such as Related Post will take your Bio’s priority. This trick will make your Bio displays before other plugins do.
Do you have an example of what it looks like?
Just thought to bring it to your notice. When I put the code on my blog, a parsing error appeared. Can you tell me the exact place in the functions.php to place the code in?
Thank You
How to know the no. of posts from each author. I mean, Is it possible to show the no. of posts by a particular author as well?
Thanks for any help!
Nice and thanks for sharing, i have written a post for adding Twitter ID in the comment box. works with wordpress theme, you can check once
Awesome recipes on this blog. Just a suggestion: if you can include a screenshot or a demo of how the output looks for all/any recipes, it would help bloggers like me!
Really cool tip. At first I had the same question as Alex did, but Lam pointed out the difference.
Hey, this code is outdated, and contain some bugs, i suggest this correction :
http://pastie.org/684855
regards
No need of CSS codes here? Interactiveness?
Can you tell me the exact place in the functions.php to place the code in?
thanx…
but i get some error…..and how to configure css?
How do I configure the look and feel? This code worked like a charm, however, I want to know How do customize the look..
I used it in my theme and found that the author information is being displayed on the home page as well at the bottom of every post which was not looking good…In order to solve this I put a condition to show the author bio only if the current page is a single post page. Here is how i did that….
function get_author_bio ($content=”){
global $post;
$post_author_name=get_the_author_meta(“display_name”);
$post_author_description=get_the_author_meta(“description”);
$html=”\n”;
$html.=”\n”;
$html.=”\n”;
$html.=”Author: “.$post_author_name.”\n”;
$html.= $post_author_description.”\n”;
$html.=”\n”;
$html.=”\n”;
$content .= $html;
return $content;
}
if (is_single()) {
add_filter(‘the_content’, ‘get_author_bio’);
}
It would be nice in future to put a little bit more information rather than “Open your functions.php file and paste the following code. That’s all you have to do!”.
Not everyone who reads your blog will understand the code as well and they could mess up their blogs..
@Dean Saliba : Most WordPress users who like to play with hacks knows what the functions.php file is. However, when someone don’t know, he just have to ask like you did
The functions.php file is a file located under your theme directory (ie. wp-content/yourtheme/ ) and it allow you to insert functions into your WP theme.
If the file doesn’t exist, just create one that you’ll name functions.php.
Any way to exclude certain autors i.e. Admin ?
Trackbacks: