How to Rewrite Guest Author Name with Custom Fields in WordPress
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:

Comments
12 Responses to “How to Rewrite Guest Author Name with Custom Fields in WordPress”Share Your Opinions
Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!
Please make sure that you have read our Comment Policy.










Even though, I’m not a huge fan of custom fields period, I like the idea behind your snippet.
I was actually thinking about exactly this issue (adding a user for every guest author) just the other day.
I’d like to try this suggestion but it would be helpful for this beginner to know where the “functions.php” file is located and then, exactly where to insert the code. I tried to edit the Theme Functions file (it said “functions.php in parentheses) but got a warning that this file cannot be edited. Is the file I want on the server?
thanks,
Carl
Hey Carl,
We have covered where functions.php file is located in our theme cheat sheet for beginners. You will need to insert this code right before ?> where the file ends.
Thank you so much for this article; I was going nuts trying to get various writers sorted out for my website and now I can add author names so easily. I use custom fields for all my requirements which affected ‘the_author()’ and stopped author names being shown at all. The above has allowed me to have the authors appear and highlight different authors as they write.
Sorry for rambling! You have saved me a lot of work…thanks!
I’ll also tweet it for you!
Thanks so much for this post – this was exactly what I’ve been looking for. Brought up my issue here and used a modified version of your code to fix it. Thanks again!
Exactly what I needed! Thank you very much
I was really hoping this would work for me but hmmm didn’t work
What is not working? We have this running on WPBeginner site and it works just fine. We are just calling a simple custom field.
I tried this too, pasting the code into the top of my includes/functions.php file. I got a php error, saying that something was an invalid filter. Does this work with WordPress 3.0?
I hope I can get it to work, I’m porting a site to WordPress form Joomla and this is the only thing I’m missing.
It’s working fine with WP 3.0
Is it possible to include a field for the author’s description as well? I already have a plugin (wp-gravatar) that posts the author’s description at the end of a post. However, I want to be able to post the guest author’s description without having to create new accounts everytime. Is it possible to combine the method you described above to make it do this?
Yes, it is possible to do the guest author description via custom field. You can set a conditional statement if there is x custom field, then display the custom field text, if not then display wp-gravatar.