How to Rewrite Guest Author Name with Custom Fields

Have you ever had a guest post on your blog? How do you go about giving the author full credit? We have seen many sites where they add an author profile box either above the post or below the post. But even with the guest author box, the author name field would still show the site author. Some bloggers create entire new author profiles for their guest authors in order to display the right name. We think that it is pointless to create extra user profiles if you know that this guest author will only post once.

The trick we are sharing in this article will allow you to show guest author’s name by simply entering a custom field in your post.

Open your functions.php file and paste the codes below:

    add_filter( 'the_author', 'guest_author_name' );
    add_filter( 'get_the_author_display_name', 'guest_author_name' );

    function guest_author_name( $name ) {
    global $post;

    $author = get_post_meta( $post->ID, 'guest-author', true );

    if ( $author )
    $name = $author;

    return $name;
    }

Now every time that you are posting a guest post, just make sure that you add a custom field called guest-author and it will replace the author’s name with the text that you put in that custom field.

Example:

Adding guest author name in the custom field