Hack: Hide Author Names

Suppose you’d rather just have all your posts attributed to “Staff” instead of the actual author names, which could be for internal use only.

You can do this with a bit of code in your own swiss-army-knife plugin or simply in the theme functions.php file. Here’s the code:

 

add_filter( 'the_author', 'no_author' );
add_filter( 'get_the_author_display_name', 'no_author' );
function no_author( $name ) {
	return "Staff";
}

This just will replace the author name with the word “Staff” or whatever you want. It is often a better alternative than editing the theme directly to remove or hard-code the author byline.

Notice that $name is passed in as the parameter to the function. You could use that to check the name and only return something special in some cases. For instance, this will show the author normally for everyone except “wombat” and “joe.”

add_filter( 'the_author', 'no_author' );
add_filter( 'get_the_author_display_name', 'no_author' );
function no_author( $name ) {
        if ($name == "wombat") return "Staff";
        if ($name == "joe") return "Staff";
	return $name;
}

One Reply to “Hack: Hide Author Names”

Leave a Reply

Your email address will not be published. Required fields are marked *