I need to return the comment form as a string so I can append it to a modal with js.

$commenter = wp_get_current_commenter();
    $req = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );
    $fields =  array(
        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Your name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
            '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email address' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
            '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /><br /><span>We'll only send you an email when someone has commented on your post.</span></p>',
    );

    $comments_args = array(
        'fields' =>  $fields,
        'title_reply'=>'Post a comment',
        'label_submit' => 'Post comment'
    );

comment_form($comments_args, intval($_SESSION['thePostId']));

Have tried get_comment_form() but I get error.

Can anyone help cheers

Read more here: Can’t seem to return comment as a string


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: