Edit Wordpress comment form (just add a class to the text inputs)
I'm using the default twenty_ten theme that comes with the latest Wordpress and modifying it. I just want to add a class to certain text inputs within the new comment form (specifically to add
class="text"to make it play nice with Blueprint CSS framework).
I can't locate the place to do this. Not au fait wit开发者_运维百科h PHP but able to work my way around it in most cases - just can't seem to locate the form here.
Any help appreciated.
The comment form is output by the WordPress comment_form() function. To add a CSS class to specific inputs, you can change the $fields
argument when it's called from the bottom of the TwentyTen comments.php file.
In the example below I've added class="text"
to the author input field:
<?php
$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input class="text" 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' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' . '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);
comment_form(array('fields'=>$fields));
?>
Alternatively you could create a filter in your theme's functions.php that added the input class for you:
function my_comment_fields($fields) {
foreach($fields as $field){
// Add the class to your field's input
}
return $fields;
}
add_filter('comment_form_default_fields','my_comment_fields');
Login in to you Control Panel. Open wp-includes folder from File Manager. Select comment-template.php and Click Edit. Go to the line 1541 or search for ‘’ Near to this you can see “Your email address will not be published. Required fields are marked *”
$fields = array(
'author' => '<p>' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />',
Read more at aTechguide.com http://atechguide.com/edit-comment-form-wordpress
精彩评论