Hi @inthedistance,
Glad you like it!
Chaplin doesn’t differ from other themes in how comment_form()
is used, so the normal filters should work as expected. I did try the code included in the article you linked to though, and it seems that the code in the article includes a few bugs (it uses undefined variables in the function hooked to the comment_form_default_fields
filter, for example).
To remove the URL field and move the label to the placeholders, add the following code to the functions.php
file in your child theme:
// Comment form: Remove URL, add placeholder to Name and Email fields
function chaplin_child_filter_comment_form( $fields ) {
// Remove the URL field
unset( $fields['url'] );
// Get variables used in the field array
$req = get_option( 'require_name_email' );
$html_req = ( $req ? " required='required'" : '' );
$html5 = current_theme_supports( 'html5', 'comment-form' );
$commenter = wp_get_current_commenter();
// Modify the author field
$fields['author'] = '<p class="comment-form-author">' . '<label class="screen-reader-text" for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' placeholder="' . __( 'Name' ) . ( $req ? ' *' : '' ) . '" /></p>';
// Modify the email field
$fields['email'] = '<p class="comment-form-email"><label class="screen-reader-text" for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $html_req . ' placeholder="' . __( 'Email' ) . ( $req ? ' *' : '' ) . '" /></p>';
return $fields;
}
add_filter( 'comment_form_default_fields', 'chaplin_child_filter_comment_form' );
// Comment form: Add placeholder to comment field
function chaplin_child_filter_comment_form_defaults( $defaults ) {
$defaults['comment_field'] = '<p class="comment-form-comment"><label class="screen-reader-text" for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required" placeholder="' . _x( 'Comment', 'noun' ) . '"></textarea></p>';
return $defaults;
}
add_filter( 'comment_form_defaults', 'chaplin_child_filter_comment_form_defaults' );
I noticed that some Chaplin style issues cropped up when modifying the comment form fields. It’s caused by the targeting in the comment form styles being incorrect, and should be fixed in version 2.3.1.
Let me know if the code above does the trick.
— Anders