Skip to content

How to style wordpress default comment form for TwentyTen?

Go to your theme open comments.php if you have one:

and find the line:

comment_form();

Replace it with this code which you could change as you like:

$commenter = wp_get_current_commenter();

$fields =  array(
 'author' => '<p>' . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /><label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
 '</p>',
 'email'  => '<p><input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
 '</p>',
 'url'    => '<p><input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /><label for="url">' . __( 'Website' ) . '</label>' .
 '</p>',
);

$defaults = array(
 'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
);

comment_form($defaults);

For more information check the wordpress docs: http://codex.wordpress.org/Template_Tags/comment_form

Published inCodingWordpress

One Comment

  1. Shaun

    Hey this is really useful, thanks!
    Curious though, how do I change the php so that the label comes first wrapped in its own p tag, before the input field which Id like to also wrap in a p tag? I tried simply copy pasting the label part in front of the input field and then wrapping p tags around the label but it broke my theme. I dont really have a lot of php experience yet.
    thanks.

Comments are closed.