Last active
July 30, 2019 07:56
-
-
Save ivanildodias/436c6083175cb4b2ba8a to your computer and use it in GitHub Desktop.
Remove "novalidate" attribute in default WordPress Comment Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ob_start(); | |
$commenter = wp_get_current_commenter(); | |
$req = get_option( 'require_name_email' ); | |
$aria_req = ( $req ? " aria-required='true'" : '' ); | |
$html_req = ( $req ? " required='required'" : '' ); | |
$span_req = ( $req ? ' <span class="required">*</span>' : '' ); | |
comment_form( array( | |
'title_reply' => __( 'Leave your thoughts', 'issimple' ), | |
'comment_notes_after' => '', | |
'fields' => apply_filters( 'comment_form_default_fields', array( | |
'author' => '<div class="comment-form-author form-group">' . '<label for="author">' . __( 'Name', 'issimple' ) . $span_req . '</label> ' . | |
'<input id="author" class="form-control" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="40"' . $aria_req . $html_req . ' /></div>', | |
'email' => '<div class="comment-form-email form-group"><label for="email">' . __( 'Email', 'issimple' ) . $span_req . '</label> ' . | |
'<input id="email" class="form-control" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="40" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></div>', | |
'url' => '<div class="comment-form-url form-group"><label for="url">' . __( 'Website', 'issimple' ) . '</label> ' . | |
'<input id="url" class="form-control" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="40" /></div>', | |
) ), | |
'comment_field' => '<div class="comment-form-comment form-group"><label for="comment">' . __( 'Comment', 'issimple' ) . ' <span class="required">*</span></label> ' . | |
'<textarea id="comment" class="form-control" name="comment" cols="45" rows="8" aria-describedby="form-allowed-tags" aria-required="true" required="required"></textarea></div>', | |
'class_submit' => 'submit btn btn-default', | |
) ); | |
$comment_form = ob_get_contents(); | |
ob_end_clean(); | |
echo str_replace( 'novalidate', '', $comment_form ); |
You can remove html 5 support just before printing out your comments form
// removes "novalidate" attribute from default output form
remove_theme_support('html5');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can remove
novalidate
attribute with this simple Javascript:No jQuery needed.
You can include the following code to run script just on posts:
footer.php