Wordpress

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:

01 add_filter( 'the_author', 'guest_author_name' );
02 add_filter( 'get_the_author_display_name', 'guest_author_name' );
03
04 function guest_author_name( $name ) {
05 global $post;
06
07 $author = get_post_meta( $post->ID, 'guest-author', true );
08
09 if ( $author )
10 $name = $author;
11
12 return $name;
13 }

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:

Rewrite Guest Author's Name using Custom Fields in WordPress

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s