AuthorSection

Have you ever had a guest blogger contribute to your site? What is the best way to give the author full credit? We’ve encountered a lot of sites that include an author profile box either above or below the post. However, even if the guest author box was checked, the site author’s name would still appear in the author name field. In order to reflect the correct name, some blogs construct entirely new author profiles for their guest authors. If you know that this guest author will just publish once, we believe it is unnecessary to create additional user profiles.

Advertisements

The approach we’ll teach you in this article will allow you to display the name of a guest author by simply adding a custom field to your post.

Paste the following codes into your functions.php file:

1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}
Advertisements

Now, whenever you publish a guest post, simply add a custom field called guest-author, and the author’s name will be replaced with the text you enter in that custom field.

Example:

Guest Author

Advertisements

Leave a Reply