Post Pic

WordPress hack: Automatically insert author bio on 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!

7 Responses

Sep 07 2011 17:26

Thanks, super-helpful! You left one div unclosed, you should add another line like:

$html.=”\n”;

Sep 07 2011 17:27

Well, that comment wasn’t formatted correctly, so you’ll have to use your imagination. What I mean to say is: Close the div.

Jul 07 2012 23:54

This is great! I don’t like using plugins if I can add a function to my blog. :)

Thanks for sharing. I have a question. Is there a way to have this code only show the bio on Posts and not Pages?

Cheers!

Jul 14 2012 02:54

This is almost exactly what I need. Currently we have about 17 sites and we posts newsletters in one place, then use the Atom rss feed to distribute and repost them on the other 16 sites. But when I do this, the byline is gone and it is posted as “admin” or another user.

When I use your awesome function, on the 16 sites the newsletter gets distributed to it spits out the author name and bio as “admin”, the account that imported it. Is there anyway to retain the original information?

Jan 10 2013 10:38

if i want to add same author but with different bio, how can i do it?

Jan 21 2013 19:00

This code does not work for me. Its creating some kind of error :(

Feb 26 2013 19:02

Same problem with me. After adding code it’s showing blank page. Even mail domain shows blank page .

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox