tags:

views:

33

answers:

1

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 with PHP but able to work my way around it in most cases - just can't seem to locate the form here.

Any help appreciated.

A: 

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');
Pat
Brilliant, thanks for your comprehensive answer.
Tom