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

admin2025-06-02  0

I insert the name of parent comment's author in child comment

   if( $comment->comment_parent )
    comment_author( $comment->comment_parent );

How to insert a comma to this construction in function.php?

Example,

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

do not work.

Thanks

I insert the name of parent comment's author in child comment

   if( $comment->comment_parent )
    comment_author( $comment->comment_parent );

How to insert a comma to this construction in function.php?

Example,

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

do not work.

Thanks

Share Improve this question asked Mar 9, 2019 at 20:08 Андрей СахаровАндрей Сахаров 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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 ', ';
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748825191a314034.html

最新回复(0)