Display Guest Author’s Name via Custom Field

Many Blogs are now having guest posts on their site. Some of these guest authors are one-time only authors, so there is no point in creating a separate profile for them just so you can display their name in the post. The smarter way to do this is by using the following code.
Open you single.php, or page.php in your template and add the following code where you display the author name:
1 | <?php $author = get_post_meta( $post ->ID, "guest-author" , true); |
2 | if ( $author != "" ) { |
3 | echo $author ; |
4 | } else { |
5 | the_author(); |
6 | } ?> |
This code will look for the custom field called guest-author if it is found, then it will display that name, otherwise it will display the_author function meaning the person who actually published it meaning you.
Note: You might have to remove the original the_author function before you place this.
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:
Display Guest Author’s Name via Custom Field
Reviewed by Unknown
on
8:41 PM
Rating:

No comments: