How to insert a comma to the child comment construction in function.php?

comment_author prints the author. It doesn’t return anything.

So if you do this:

if ( $comment->comment_parent )
    comment_author( $comment->comment_parent ) . ', ';

Then, what it really does is:

  • check if comment has parent and if so:
    • print its author
    • get the result of function comment_author (which is empty) and concatenate it with string containing ‘, ‘
    • don’t do anything with that string

And what you want is this:

if ( $comment->comment_parent ) {
    comment_author( $comment->comment_parent );
    echo ', ';
}