Display another field as 'Node author' if node posted anonymously Currently on my D6 site registered as well as anonymous users can post articles. A custom text field has to be filled by unregistered users while creating an article. This text field's value is shown as Node author for anonymous posters. 

Now I am all set to upgrade this site to D7. I tried using the following snippet to display custom text field value as the 'node author' if posted by Anonymous user, But it has some issues...


menu_get_object() works only for full node view and not for teasers etc.
It also changes $name every where on the page eg: for unregistered comments too.


function mytheme_username_alter(&$name, $account) {
  $node = menu_get_object();
    if($account->uid == "0") {
      $name = $node->field_custom_author['und'][0]['value'];
     }
}

Question: How can I tweak this function to display custom text field's value as 'Node Author' if the node is created by an anonymous user, without changing $name elsewhere on the page?

If there's a better function/solution than this, i am all open to try that too.
You have two viable options:


In theme system, use either node.tpl.php file to do it, or probably better template_preprocess_node(&amp;$variables). I'll discuss function as that's what I prefer. When using function, copy it to your own template.php, renaming to mytheme_preprocess_node(&amp;$variables). As a source, use parent theme if it implements it. If not, or if there is no parent theme, use link I provided above.

Then find a line like this:

$variables['node'] = $variables['elements']['#node'];


and after it modify $variables['node'] as you see fit. 
Use Computed Field to create a field that shows author's name, and in case of anonymous authors displays arbitrary text. Turn off displaying author and use this field instead.