WordPress hack: Adding a bio block to a post
If you have multiple writers on your blog or if you are accepting guest articles and you want to give this person some exposure, a little box containing a short bio will do perfectly.
The only problem is that bios are not standard in WordPress. This article will tell you how to hack your own bio box into WordPress without using a single plugin! A great way to start developing in WordPress.
Hack your template
First thing we need to do is to hack a file in your theme’s template. The file we want to edit is called “single.php” in most WordPress themes.
Open up this file.
This is the template file that shows a single post. Typically the template file has the following code somewhere “the_content()” looks for this.
Beneath this line of code paste the following:
<?php
if (get_post_custom_values("bio")) {
?>
<div class='writer_bio'>
<img src='<?php the_author_aim(); ?>' alt='' />
<?php the_author_description(); ?>
</div>
<?php
}
?>
Adding a bio to a writer
We now want to add / edit writers, you can create them in the user panel of WordPress. I am guessing you are already using this to display the author’s name on your blog. We can use the fields available per user to set the bio.
Go and edit an existing user that has an article posted (You can change the user that posted the article when you edit an article.)
Now fill in the “Biographical Info” text area with the HTML to go into the bio block.
My bio, for example is: “Gaya Kessler is a 21 year old web developer writing about a kinds of thing. He’s the editor of <a href=”http://www.fuelyourcoding.com”>Fuel Your Coding</a> and owner of <a href=”http://www.gayadesign.com”>Gaya Design</a>. You can also <a href=”http://www.twitter.com/gayadesign”>catch him on twitter</a>.”
To add the avatar we need to fill in the “aim” field. I am not using this field anywhere in the theme, but now I am going to use it in the bio. Put the absolute path to the image here, eg: “http://fuelyourcoding.com/files/writer-rob.png”.
Now all there is left to do is enable the bio on a post. To do this you only need to add a custom field to a post.
Go to a post you want to add bio to and create a name custom field called “bio” and give it the value “1″.
If all went well the bio should now be visible in that post!
Is that all?
Jep! The hacking is done.
You might want to add some styling though, to make it more appealing to the eye.
Good luck with this easy hack!
Gaya Kessler is a 22 year old web developer writing about all kind of things. He’s the owner of Gaya Design. You can also catch him on twitter.


Really nice tutorial, Wondered how to do this but not really looked into it, its alot easier than I thought :D Thanks!
Awesome tutorial Gaya, so quick and easy even I (non programming savvy) can do it!
Hack? Really…? I didn’t know simply using standard WP calls are considered hacks.
I’m like Steve, I’ve been meaning to look into this but had no idea it would be so easy. Thanks a lot!
Great to see people can use this simple adjustment to wordpress :D
What about if I have different authors for my blog? How do I put up different display photo? Do I use custom fields to pull the photo?
I’m new to coding.
Any help is appreciated.
Hi Jason,
You just create a new user for each author and give them the role of Contributor (If you don’t want them editing posts, don’t tell them what their password is!). Follow Gaya’s explanation on how to populate the author bio and author image.
Once that is done, simply change the “Post Author” at the bottom of the Post Editing page to the author who wrote the article, save your changes, and the rest should work like clockwork!
Let me know if you have any more questions!
Hm, but Gaya changed the AIM field to an absolute path.
“To add the avatar we need to fill in the “aim” field. I am not using this field anywhere in the theme, but now I am going to use it in the bio. Put the absolute path to the image here, eg: “http://fuelyourcoding.com/files/writer-rob.png”.”
So if it’s an absolute path, it’ll display the same author picture no matter what bio I’ve change to.
@Jason The aim field is still specific to the author. So if you supply a different path (even absolute path) on each Author/User you will get different photos for each. The template tag “the_author_aim()” will return that field for whoever you set as the post author.
Ah… Got it. Thanks! I thought the AIM is only allowed to put the AIM ID. Didn’t know we can use it to put paths.
Thak you. :)
@Jason No problem. The AIM field is supposed to be for AIM user ids… that’s why this is called a WP Hack :)
Great tip but adding custom fields to every post may get tiring after awhile so I choose the following to call the image:
<img src=”/images/.jpg” alt=”" class=”alignleft”/>
If your post will always have an author then you can just pass any of the values you filled out in your author profile to bring up a specific named pic.
Feel free to read the complete entry for more info:
http://gabediaz.com/blog/displaying-author-pic-and-bio-in-your-wordpress-post/
@Gabe WordPress ate your php, so thanks for the link! The decision you made with your solution is that every single post would have a bio. Here on Fuel Your Coding, some posts have bios and some do not, which is why the custom field is helpful. Perhaps a custom field “hide_bio” would work better in your situation.
Also if you have control over which authors you publish, you could generate an avatar based on their email address: http://codex.wordpress.org/Using_Gravatars
@Douglas Actually yes, different solutions for different issues.
For a one to one basis the custom field solution works great.
My solution came about needing to add a bio and pic to over 80 posts for an author in a specific category who did not have a Gravatar account. Although yes any changes to single.php would effect your entire site’s single posts…you can use custom “post” templates to have certain category posts appear different than others.
There has to be a in between solution for automated post to post bio/pic with no regards to the category they are in. The reason I say automated is that although many people are WP savvy, there are many more out there who are not and the only direction they can take is “Write in that big box and then click save or publish.”
Keep up the great work, can’t wait to read more!
Will this work if your blog is hosted on WordPress.com? If so, where would one find the “single.php” file?
Yep. I’m a newbie. :)
Thanks in advance!
http://twitter.com/suedecrush
I believe this will help.
http://bootstrap.pk/tutorials/how-to-add-about-author-block-to-wordpress-post-page-with-gravatar/
hey what a great tutorial. A great experience.
Why you don’t make a plugin? It’s better for me coz I’m newbie :)
Hi thanks for a great idea. I am new at this so forgive me for the nubness:
At the end of your post you mentioned that we might want to add some styling. How do i do that?
In your code we are calling a class=’writer_bio’ is that were I can do this? where do i store this class? could you elaborate on this part?
The code works like a charm so thanks
Thanks for the details and learn alot from the comment trail too.
Thanks, I have really searching for this!… i have everything working, but i can seem to make the “AIM” image float to the left, so that my text can be flush next to it… my image is on the first line.
I styled the ‘Writer_bio’ class, but how can i style the “AIM” class or what ever it is called.
thanks
Not sure what theme you are using, but in Yacht Help Desk all I did was style the Writer_bio class with float left commend. Both for the Paragraph and image.
#writer_bio{
border:1px solid #CECFD0;
background: #EFEFEF;
margin:0 auto;
margin-bottom:10px;
overflow:hidden;
float:left;
}
#writer_bio img{
margin:0;
padding:10px;
float:left;
border:0;
}
Maybe this will help
thanks a lot :D
Thanks heaps! There is alos a plug in called weasel something or other which prevents Wordpress from stripping the html from the bio info box – I found this really useful to add other links eg. to FB :)