WordPress似乎将注释字段与其他字段分开处理。如果你看comment_form()
在里面wp-includes/comment-template.php
, 你可以看到这个。
可以设置$defaults[\'comment_field\']
在中出错alpha_comments_defaults()
然后将注释字段标记添加到$fields[\'comment_field\']
在里面alpha_comments_fields()
但这可能会给插件带来麻烦。
我已经移动了一些东西,并添加了代码来处理您请求的字段排序。
function alpha_comments_defaults( $defaults ) {
$defaults[\'id_form\'] = \'\';
$defaults[\'id_submit\'] = \'\';
$defaults[\'comment_field\'] = \'<p class="comment-form-comment"><label>\' . _x( \'Comment\', \'noun\' ) . \'</label>\' .
\'<textarea name="comment" cols="45" rows="8" aria-required="true"></textarea></p>\';
return $defaults;
}
add_filter(\'comment_form_defaults\', \'alpha_comments_defaults\');
function alpha_comments_fields( $fields ) {
$commenter= wp_get_current_commenter();
$req = get_option( \'require_name_email\' );
$aria_req = ( $req ? " aria-required=\'true\'" : \' \' );
$fields = array(
\'author\' =>
\'<p class="comment-form-author"><label>\' . __( \'Name\', \'domainreference\' ) . ( $req ? \'<span class="required">*</span>\' : \'\' ) . \'</label> \' .
\'<input name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) . \'" size="30" \' . $aria_req . \' /></p>\',
\'email\' =>
\'<p class="comment-form-email"><label>\' . __( \'Email\', \'domainreference\' ) . ( $req ? \'<span class="required">*</span>\' : \'\' ) . \'</label> \' .
\'<input name="email" type="text" value="\' . esc_attr( $commenter[\'comment_author_email\'] ) . \'" size="30" \' . $aria_req . \' /></p>\',
\'url\' => \'\',
);
return $fields;
}
add_filter(\'comment_form_default_fields\', \'alpha_comments_fields\');
// Reorder comment fields.
// http://wordpress.stackexchange.com/a/218324/2807
function alpha_move_comment_field( $fields ) {
$comment_field = $fields[\'comment\'];
unset( $fields[\'comment\'] );
$fields[\'comment\'] = $comment_field;
return $fields;
}
add_filter( \'comment_form_fields\', \'alpha_move_comment_field\' );