28.05.2010 in Home > Internet > WordPress by Namit Gupta 11

Adding About the Author Box Below each Post in WordPress

Whenever a reader likes any article he looks for the author, to know more about him, to connect with him/her. About the Author Box below the post is the best place to display some information about the author. Especially in a multi-author blog each author should get proper credits for his/her post(s).

A small thumbnail, a one line description with some links to the Author’s online social accounts does great. In this article I’ll be providing you with the procedure to add About the Author Box at the bottom of each post in WordPress.

Sample Author box:
author-box-wordpress

Procedure to add an Author Box below each post in WordPress

1.) Add the following code to your theme’s Style.css file. (Dashboard->Appearance->Editor->Style.css)


/* Author Box */
#author-info { background: #eee; padding: 10px; margin: 10px 0 0 0; font-size:12px; overflow: auto; }
#author-font { font-size:19px; }
#author-image { float: left; margin: 0 10px 5px 0; border: 5px solid #DCDCE1; }

You can change the background color of the box by editing the “background: #eee” value in the above code. Replace “#eee” with any of the hexadecimal color code you wish.

2.) Copy the following code to your theme’s Function.php file. ( Dashboard->Appearance->Editor->Functions.php )

Note: Be careful while editing functions.php, put this code before closing (?>) php tag.


// Add Twitter, Facebook and Gender profile field in user profiles.
function add_twitter_contactmethod( $contactmethods ) {
// Add Twitter
$contactmethods['twitter'] = 'Twitter';
// Add Facebook
$contactmethods['facebook'] = 'Facebook';
// Add Gender
$contactmethods['sex'] = 'Sex(m/f)';
return $contactmethods;
}
add_filter('user_contactmethods','add_twitter_contactmethod',10,1);

This code will add Twitter, Facebook and Gender Profile fields in user profiles.
Enter the Twitter id (example: namit_gupta), Facebook (example: namitgupta15), Gender (exaple: m)

Also see: How to set Vanity URL for Facebook Profile

3.) Copy the following code to your theme’s Single.php file. ( Dashboard->Appearance->Editor->Single.php )


<div id="author-info">
<div id="author-image">
<a href="<?php the_author_meta('user_url'); ?>"><?php echo get_avatar( get_the_author_meta('user_email'), '80', '' ); ?></a>
</div>
<div id="author-font">Article by <a href="<?php the_author_meta('user_url'); ?>" rel="nofollow" target="_blank"><?php the_author_meta('first_name');?> <?php the_author_meta('last_name');?></a></div>
<div style="line-height: 2;">
<p><em><?php the_author_meta('description'); ?></em></p>
<?php
if(get_the_author_meta('facebook') || get_the_author_meta('twitter')){
if(get_the_author_meta('sex') == "m"){
?>
<p>Connect with him on
<?php
}
if(get_the_author_meta('sex') == "f"){
?>
<p>Connect with her on
<?php
}
if(get_the_author_meta('twitter')){
?>
<a rel="nofollow" href="http://twitter.com/<?php the_author_meta('twitter'); ?>" target="_blank"><b>Twitter</b></a>
<?php
}
if(get_the_author_meta('facebook') && get_the_author_meta('twitter')){
?>
and
<?php
}
if(get_the_author_meta('facebook')){
?>
<a rel="nofollow" href="http://facebook.com/<?php the_author_meta('facebook'); ?>" target="_blank"><b>Facebook</b></a>.</p>
<?php
}
}
?>
</div>
</div><!--Author Info-->
</div>
</div>

The above code will display Author’s Name, Description, links to Twitter and Facebook Profile and website link from the user profile. So be careful while entering details in the user profiles. I am using the same code on this blog.

Feel free to comment if you experience any problem.

Related Articles

  • http://www.whitehatandroid.com/ Shekhar Sahu

    I think box with black background looks good.

    • http://www.theitechblog.com Namit Gupta

      Shekhar, It totally depends on your blog design. If you will make Author box background black you will also need to change font color to white or some other light shade for proper visibility of text.

  • http://zn3twork.com Zainab R.

    Hey Namit,

    Great resource! I've looking around everywhere for a proper code to help create an author box below each post, most of 'em didn't really work for me, but this one did.

    I just have one problem. While it appears absolutely fine at the bottom of each post, it's appearing beside my sidebar on different pages as well! For example;

    http://main.zn3twork.com/?cat=5
    http://main.zn3twork.com/?page_id=41

    Any idea on how I can fix this?

    Thanks!

  • http://www.dailytechpost.com DailyTechPost

    Great info…i was wondering how to add author info….it has surely helped me a lot….thanks for sharing :)

    • http://www.theitechblog.com Namit Gupta

      Glad, you liked it :-)

  • Bret

    Hello Namit, thank you for sharing this.
    I have a question, what if I would like to display multiple authors (co-authors) and not just one person?

    I have Co-Authors Plus plugin installed, is there a way to make this plugin work with your mod?

  • http://www.kyleclouse.com Kyle Clouse

    Namit, great post. Thank you for sharing. I was actually looking for something else but I'm glad that I came across your blog. What I am trying to do is hide or not show any author info when a post is published. I am working on a blog for a friend and on the from page we have a post. How do I get rid of the area that says "October 14, 2010 By admin Leave a Comment" I don't want to show this at the top of the post so that it stays and looks clean. Here is the blog I am referring too. Any help is appreciated. http://www.electtimo.com

    • http://www.theitechblog.com Namit Gupta

      Thanks Kyle for your comment. I am glad. What you want to do is a very simple job. Goto Dashboard -> Appearance -> Editor -> Single.php, and delete the required lines of code, it will be something like 'date'. Save the file, now the date and author will not be shown. Do ensure to make proper backup of single.php file before doing any changes. If you experience any prob, feel free to comment. :-)

      • http://www.kyleclouse.com Kyle Clouse

        Thank you commenting back Namit! I am using the Genesis framework.

        I went to Single.php and the code that they have listed is:
        <?php
        /**
        * This file handles posts, but only exists for the sake of
        * child theme forward compatibility.
        */
        genesis();

        I tried deleting the entire code and saving and nothing happened. Any suggestions? Thanks again, Kyle

        • http://www.theitechblog.com Namit Gupta

          You will have to edit the child theme's single.php file. I suppose you are using 'Prose Child Theme', at the editor page select this theme from the drop down list at the top and edit its single.php file. Try editing it. If problem exists do let me know.