How to add author bio for guest posts in Genesis

At Deluxe Blog Tips, we have some guest posts from JayKrishna Yadav. In the end of each guest post, I display his name, bio and gravatar to let people know more about him. That author bio box is supported by Genesis framework, which I’m using for Deluxe Blog Tips. If you want to use the default Genesis author bio box, you have to create an user for your contributor, and fill in his bio. That’s good enough unless the contributor wants to show different bio in author bio box each time he writes a post, like JayKrishna Yadav does at Deluxe Blog Tips. In this post, I’ll show you how to do that with a simple meta box and a few lines of code that will replace Genesis author bio box with a custom one.

Step 1: Define meta box for guest post

To setup a meta box for guest post, I use my Meta Box plugin. The code for guest post settings is quite simple:

add_action( 'admin_init', 'dbt_guest_post_meta_box' );

function dbt_guest_post_meta_box()
{
    if ( !class_exists( 'RW_Meta_Box' ) )
        return;

    $prefix = 'gp_'; // Guest Post
    $meta_box = array(
        'title'  => 'Guest Post Settings',
        'fields' => array(
            array(
                'name' => 'Name',
                'id'   => "{$prefix}name",
                'type' => 'text',
            ),
            array(
                'name' => 'Email',
                'id'   => "{$prefix}email",
                'type' => 'text',
            ),
            array(
                'name' => 'Bio',
                'id'   => "{$prefix}bio",
                'type' => 'textarea',
            ),
        ),
    );
    new RW_Meta_Box( $meta_box );
}

I register a meta box with 3 fields: Name (text), Email (text) and Bio (textarea). The email will be used to show author’s gravatar.

If you don’t know what the code means, please look at see how to register meta box and how to define meta fields.

The result is:

guest post How to add author bio for guest posts in Genesis

Step 2: Replace Genesis author bio box by our custom one

Genesis has a filter genesis_author_box that let us change the information in author bio box. I use it to display custom author bio box:

add_filter( 'genesis_author_box', 'dbt_author_box', 10, 6 );

function dbt_author_box( $text, $context, $pattern, $gravatar, $title, $description )
{
    $name  = rwmb_meta( 'gp_name' );
    $email = rwmb_meta( 'gp_email' );
    $bio   = rwmb_meta( 'gp_bio' );

    if ( empty( $name ) || empty( $email ) || empty( $bio ) )
        return $text;

    $gravatar_size = apply_filters( 'genesis_author_box_gravatar_size', 70, 'single' );
    $gravatar = get_avatar( $email, $gravatar_size );

    $title = apply_filters( 'genesis_author_box_title', sprintf( '<strong>%s %s</strong>', __( 'About', 'genesis' ), $name ), 'single' );
    $description = wpautop( $bio );

    return sprintf( $pattern, $gravatar, $title, $description );
}

In this function, I use the helper function of meta box plugin to retrieve author information, and then pass that information to a predefined $pattern variable, which holds the HTML structure for author bio box. This makes the guest author bio box looks exactly like default author bio box.

That’s all. Let me know what you think about this method in the comments below. And if you want to do guest post at Deluxe Blog Tips, please contact me.

10 Comments

    • HI,

      Can you please hepl me, I am awaiting for your reply.

      Reply
  1. Hi thanks for this awesome post but how do I make all the outbound links as “nofollow”? I mean the ones which are inside the author bio box?

    Reply
  2. Thanks a lot. This worked and helped. How can I make more use of the meta box plugin? What other wonders can it do? I’d be glad if you can enlighten on this aspect. Thanks again.

    Reply
  3. Thanks rilwis! Now I have the most effective ways to display Author Box for each guest post in Genesis. Your method works perfectly :)

    Reply

Leave a Reply