I would like to customize the output of comment_form()
function in WordPress.
To edit fields and textarea, I used the following code and all works fine.
<?php
$req = get_option( 'require_name_email' );
$fields = array(
// redefine author field
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name:' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-user"></i></span><input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . 'aria-required="true"' . ' required /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email Address:' ) . ( $req ? ' <span class="required">*</span><br/>' : '' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-envelope"></i></span><input required id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . 'aria-required="true"' . ' required /></div></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Your Website:' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-globe"></i></span><input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div></p>'
);
$comments_args = array(
'fields' => $fields,
// redefine your own textarea (the comment body)
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . 'Comment' . '</label><textarea id="comment" name="comment" class="span12" rows="5" aria-required="true"></textarea></p>',
);
comment_form( $comments_args );
?>
This is the result:
Now, I would like to add two CSS class (class="btn btn-primary"
) for submit button; how can I do that without using jQuery?
Note:
For the solution, please read comments about answer marked with green sign.
As krizna said, you can modify your theme’s
comments.php
file to alter the output ofcomment_form()
. I think that might be your best bet in this situation.If you take a look at the Function Reference for
comment_form()
in the Codex you’ll notice that you can only modify the ID for the submit button, and not the class. There are a few tickets on Trac regarding this:If modifying
comments.php
doesn’t work for you in this situation, you can try applying one of the patches.