我不知道您为什么要删除aria-required
属性它是W3草案中的一个表单属性,处理与应用程序和残疾用户一起工作的可访问性。
无论如何,您可以通过过滤comment_form_default_fields
和comment_form_field_comment
. 下面的示例可以用作插件或主题的functions.php
文件,并将删除aria-required
属性
/* Attach the custom_comment_form_fields() function to the comment_form_default_fields hook. */
add_filter( \'comment_form_default_fields\', \'custom_comment_form_fields\' );
/* Attach the custom_comment_form_field_comment() function to the comment_form_field_comment hook. */
add_filter( \'comment_form_field_comment\', \'custom_comment_form_field_comment\' );
/**
* Remove the aria-reuqired from name and email comment fields.
*/
function custom_comment_form_fields() {
/* Get current commenter. */
$commenter = wp_get_current_commenter();
/* Check if name and email fields are required. */
$req = get_option( \'require_name_email\' );
/* Remove the aria-required attribute. */
$fields = array(
\'author\' => \'<p class="comment-form-author">\' . \'<label for="author">\' . __( \'Name\' ) . \'</label> \' . ( $req ? \'<span class="required">*</span>\' : \'\' ) .
\'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) . \'" size="30" /></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" /></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>\'
);
return $fields;
}
/**
* Remove the aria-reuqired from comment textarea field.
*/
function custom_comment_form_field_comment() {
/* Comment text area. */
$textarea = \'<p class="comment-form-comment"><label for="comment">\' . _x( \'Comment\', \'noun\' ) . \'</label><textarea id="comment" name="comment" cols="45" rows="8"></textarea></p>\';
return $textarea;
}