You can make use of the get_comment_author
filter to adjust the text displayed as comment author name according to your needs. All you need to do is to check who the post author is and then check that against the comment author.
The complete comment object is passed by reference as third parameter to the filter, we can access that object to get the comment author which we can compare to the post_author
of the post object
add_filter( 'get_comment_author', function ( $author, $comment_ID, $comment )
{
$post = get_post();
if ( $post->post_author !== $comment->user_id )
return $author;
$author = $author . ' Post author';
return $author;
}, 10, 3 );
You can adjust and add styling as needed
EDIT - from comments
As pointed out by @birgire, the get_comment_class()
sets the .bypostauthor
class for the post author comments.
if ( $post = get_post($post_id) ) {
if ( $comment->user_id === $post->post_author ) {
$classes[] = 'bypostauthor';
}
}
We can also use this to check for comments by the post author. Just a not, it may not be very reliable as it can be overriden by themes or plugins
add_filter( 'get_comment_author', function ( $author )
{
if( !in_array( 'bypostauthor', get_comment_class() ) )
return $author;
$author = $author . ' Post author';
return $author;
});