How to Rewrite Profile Author name with Guest Author Name in WordPress?

Updated on September 2, 2017

Do you accept Guest posts on your WordPress website? If so, have you ever thought of giving a credit to the guest author for the article that he/she has written. At least, until today I didn’t know how to replace the Profile author name with Guest Author name without creating additional user profile accounts. Earlier I used to provided Guest Author Name (eg. Mark Henry) at the end of the post, but still the profile author name (E.g Peter) will be visible below the title of the post. Well, few bloggers create a separate user profile for Guest authors and somehow I was not a fan of this trick. So what’s the alternative?

What about a simple hack that can make use of WordPress custom field; which will take the guest author name as value and replace the wordpress profile name in the post page? This sounds better right?

Thanks to Syed Balkhi @ Wpbeginner.com, who created the above said trick. All you need to do is, just copy the below snippet and paste in functions.php located at your theme folder.

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;
}

Thereafter, whenever you publish a guest post, just scroll down to add a custom field called guest-author and the snippet will take care of replacing the profile author name with the value you put in the custom field. How cool is that?

add guest author name
Add custom field WordPress

Was this article helpful?

Related Articles

Leave a Comment