Monday, February 22, 2016

How to Add an Author Info Box in WordPress Posts

Do you want to add an author bio box in your WordPress posts? The author bio box is a small section where you can display information about the post author with links to their website and social profiles. In this article, we will show how to add an author info box in WordPress.


Adding author info box in WordPress


Why and When You Need an Author Info Box in WordPress


Seeing an actual person behind the content helps build credibility and strengthens your sites authority among users.


For single author websites, you can just add an about me page. But for a multi-author WordPress sites, you will need to add an author info box below each post.


The author box encourages authors to interact with readers. It provides an additional incentive to authors to build their own following.


If you accept guest posts from other bloggers on your website, then an author info box will help you gain more traction on your site.


Having said that, lets take a look at how to easily add an author info box in WordPress posts.


Adding Author Info Box in WordPress Posts


There are many different ways that you can use to add an author info section. We will show you a two different plugins as well as the code method. This way you can choose a method that works best for your site.


Method 1: Author Box Below WordPress Posts Using Plugin


Most site owners want to display author information at the end of a post. Here is how you can easily display an author info box at the end of WordPress posts.


First thing you need to do is install and activate the Guerrillas Author Box plugin. For more details, see our step by step guide on how to install a WordPress plugin.


Each author on your site will need to add their biographical information and links to their user profiles. They can do this by logging in to their WordPress account on your website and then click on the Profile link from the WordPress admin menu.


User editing their own profile in WordPress


As a site administrator, you can also fill in this information yourself by editing each users profile. You will need to visit Users All User page, and then click on the edit link below the user you want to edit.


Editing user profiles by an Administrator in WordPress


You can now visit any WordPress post on your site, and you will see the author info box below the post.


Author info box added with plugin


The plugin uses the default WordPress avatar system, called Gravatar. Your authors will need to add their photo on Gravatar website. For more information take a look at our guide about Gravatar, and why you should start using it right away.


Customizing Appearance of Author Info Box


Guerrillas Author Box plugin comes with very basic CSS. It inherits the link and text colors from your WordPress theme.


However, if you want to customize it, and you are comfortable working with CSS, then you can copy the plugins default CSS and paste it in your theme or child themes stylesheet.


Here is a sample CSS that you can use as a starting point. We have changed the background color and made the author photo round instead of square.



.guerrillawrap {
background: #ECECEC;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
border: 1px solid #d0d0d0;
float: left;
padding: 2%;
width: 100%;
}

.guerrillagravatar {
float: left;
margin: 0 10px 0 0;
width: 10%;
}

.guerrillagravatar img {
border-radius:50%;
border:1 px solid #eee;
}

.guerrillatext {
float: left;
width: 84%;
}

.guerrillatext h4 {
font-size: 20px;
line-height: 20px;
margin: 0 0 0 0;
padding: 0;
}

.guerrillatext p {
margin: 10px 0 15px 0;
font-style: italic;
}

.guerrillasocial {
float: left;
width: 100%;
}

.guerrillasocial a {
border: 0;
margin-right: 10px;
}

This is how author info box looked on our demo website after applying this CSS. Yours may look slightly different depending on the fonts and colors used by your WordPress theme.


Author info box with rounded avatar


Method 2: Author Info in Sidebar Widget For Single Posts


The above method is great if you wanted to display the author info below posts.However, some of you may want to display author bio in the sidebar or any widget ready area.


Here is how you can display author info in a sidebar widget.


First thing you need to do is install and activate Meks Smart Author Widget plugin.


Upon activation, you need to visit Appearance Widgets page. There you will find Meks Smart Author under the list of available widgets. Add this widget to the sidebar where you want to display the author information.


Smart author widget


The widget comes with a number of options. Most important option that you need to check is the checkbox next to Automatically detect author option.


Auto detect author widget


Click on the save button to store your widget settings. You can now visit your website to see the author information widget in action.


Author info widget in WordPress


This plugin also fetches user information from their WordPress profile. Your authors will need to fill their biographical information.


Method 3: Adding Author Info Box Using Code


Both methods described above rely on plugins. If for some reason you need to add author info box manually, then here is how you can do it.


First you need to add this code to your themes functions.php file or a site-specific plugin.



function wpb_author_info_box( $content ) {

global $post;

// Detect if it is a single post with a post author
if ( is_single() && isset( $post->post_author ) ) {

// Get author's display name
$display_name = get_the_author_meta( 'display_name', $post->post_author );

// If display name is not available then use nickname as display name
if ( empty( $display_name ) )
$display_name = get_the_author_meta( 'nickname', $post->post_author );

// Get author's biographical information or description
$user_description = get_the_author_meta( 'user_description', $post->post_author );

// Get author's website URL
$user_website = get_the_author_meta('url', $post->post_author);

// Get link to the author archive page
$user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author));

if ( ! empty( $display_name ) )

$author_details = '

About ' . $display_name . '

';

if ( ! empty( $user_description ) )
// Author avatar and bio

$author_details .= '

' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '

';

$author_details .= '';

} else {
// if there is no author website then just close the paragraph
$author_details .= '

';
}

// Pass all this info to post content
$content = $content . '
' . $author_details . '
';
}
return $content;
}

// Add our function to the post content filter
add_action( 'the_content', 'wpb_author_info_box' );

// Allow HTML in author bio section
remove_filter('pre_user_description', 'wp_filter_kses');


This code simply fetches the author information and displays it below WordPress posts. You need to style this author info box so that it looks nice and matches your WordPress theme.


You can use this CSS into your theme or child themes stylesheet. Feel free to modify it to meet your needs.



.author_bio_section{
background: none repeat scroll 0 0 #F5F5F5;
padding: 15px;
border: 1px solid #ccc;
}

.author_name{
font-size:16px;
font-weight: bold;
}

.author_details img {
border: 1px solid #D8D8D8;
border-radius: 50%;
float: left;
margin: 0 10px 10px 0;
}

This is how the author info box looked on our demo site.


Manual author info box


We hope this article helped you add author info box in WordPress posts. You may also want to see our guide on how to add or remove capabilities to user roles in WordPress.


If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.


The post How to Add an Author Info Box in WordPress Posts appeared first on WPBeginner.

No comments:

Post a Comment