WordPress tutorials: Guest author custom field

Wpsnipp – Adding this code to your functions.php file of your wordpress theme will let you add a custom field guest-author enter this authors name in the value field to change the author of the blog post.This trick will let you replace the author name with a custom field.

 

 

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

Leave a comment