The code below will create a plugin called ‘Substitute Author’ when copied to a file wp-content/plugins/substitute_author/substitute_author.php.
It reads a Custom Field named sa_author from a post and substitutes the value of the field for the Author name as shown by the_author(). Just add that Custom Field to your posts with the name you want substituted.
<?php
/*
Plugin Name: Substitute Author
Version: 0.1
Description: Substitutes an Author name from a Custom Field
Use the custom field sa_author with a value of the substitute Author's name.
Author: Mac McDonald
*/
?>
<?php
/* Version check */
global $wp_version;
$exit_msg='Substitute Author requires WordPress 2.8 or newer. <a href="https://codex.www.ads-software.com/Upgrading_WordPress">Please update!</a>';
if (version_compare($wp_version,"2.5","<")) {
exit ($exit_msg);
}
function sa_substitute_author_filter ($author_name) {
global $post;
$custom_author = get_post_meta($post->ID,'sa_author',true);
if ($custom_author) $author_name = $custom_author;
return $author_name;
}
add_filter('the_author', 'sa_substitute_author_filter');
?>