Working with the WordPress comment_form() can’t echo content

I am trying to echo the comment_form() as a string so it can be returned with an ajax request.

Can’t seem to figure it out.

Here is some code:

$response .= '
            <div class="modal fade" id="commentsModal" tabindex="-1" role="dialog" aria-labelledby="commentsModalLabel">
              <div class="modal-dialog" role="document">
                <div class="modal-content">
        ';
                $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'
                );

                $response .= comment_form($comments_args);
        $response .= '
                </div>
              </div>
            </div>
        ';

Anyone know how I can get the comment form as a string.

Cheers

Read more here: Working with the WordPress comment_form() can’t echo content

Leave a Reply

Your email address will not be published. Required fields are marked *