Posted By

FXDB on 10/12/11


Tagged

wordpress


Versions (?)

Rewrite Guest Author’s Name with Custom Fields


 / Published in: PHP
 

In Functions.php: Now many blogs are publishing other authors also known as guest authors. A lot of these guest authors are one time writers. In this scenario, it is not feasible to create user accounts for them. This trick will let you replace the author name to guest author with the use of a custom field.

  1. add_filter( 'the_author', 'guest_author_name' );
  2. add_filter( 'get_the_author_display_name', 'guest_author_name' );
  3.  
  4. function guest_author_name( $name ) {
  5. global $post;
  6.  
  7. $author = get_post_meta( $post->ID, 'guest-author', true );
  8.  
  9. if ( $author )
  10. $name = $author;
  11.  
  12. return $name;
  13. }

Report this snippet  

You need to login to post a comment.