0

One can reply to a comment using Reply link, below each comment item in comments list.

According to codex, by clicking that link and using comment_form_title function like this:

$replytext = 'Leave a Reply to %s';      // %s = author
comment_form_title( $noreplytext, $replytext, $linktoparent );

You can have a comment form title as Leave a Reply to [author's name].
I would like to find a way in which you have this output instead:

Leave a Reply to [comment's excerpt]

where comment's excerpt is the comment's first few words.

1 Answer 1

0

Finally I found a way and I am posting it here to address any further requests for such a workaround.

You may add a customized version of comment_form_title function to your theme's functions.php file and call it in your theme's comments.php file.

function my_comment_form_title( $linktoparent = true ){
    global $comment;
    $noreplytext = __( 'Leave a Reply' );
    $replytext = __( 'Leave a Reply to %s' );
    $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
    if( 0 == $replytoid ){
        echo $noreplytext;
    }else{
        $comment = get_comment( $replytoid );
        $excerpt = get_comment_excerpt( $replytoid );
        $title = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . $excerpt . '</a>' : $excerpt;
        printf( $replytext, $title );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.