Customise Guest Post Author

If you have guest posts on a site, then sometimes you just want to show the author as a guest author, without creating an account for them. The code below, added to your functions.php file, allows you to choose what the author will show up as by adding a custom field of guest-author.

function guest_author_name( $name ) {
    global $post;

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

    if ( $author )
    $name = $author;

    return $name;
}
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );

This can be expanded on to also support guest-email for gravatars, and guest-bio for a per post customisation of an author box.

Speak Your Mind

*