I’m not sure why you would want to remove the aria-required
attribute. It is a form attribute in draft at W3 that deals with accessibility for working with applications and handicapped users.
Anyway, you can remove it by filtering the comment_form_default_fields
and comment_form_field_comment
. The example below can be used as a plugin or in your theme’s functions.php
file and will remove the aria-required
attribute.
/* 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;
}