Created
September 13, 2018 22:56
-
-
Save TanvirAmi/61ddef93fcf1d0c2f35847ca0bf384ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* Customize comment form default fields. | |
* Move the comment_field below the author, email, and url fields. | |
*/ | |
function custom_comment_form_default_fields( $fields ) { | |
$commenter = wp_get_current_commenter(); | |
$user = wp_get_current_user(); | |
$user_identity = $user->exists() ? $user->display_name : ''; | |
$req = get_option( 'require_name_email' ); | |
$aria_req = ( $req ? " aria-required='true'" : '' ); | |
$html_req = ( $req ? " required='required'" : '' ); | |
$html5 = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : false; | |
$fields = [ | |
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name CUSTOMIZED', 'textdomain' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . | |
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', | |
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email CUSTOMIZED', 'textdomain' ) . ( $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"' . $aria_req . $html_req . ' /></p>', | |
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website CUSTOMIZED', 'textdomain' ) . '</label> ' . | |
'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', | |
]; | |
return $fields; | |
} | |
add_filter( 'comment_form_default_fields', 'custom_comment_form_default_fields' ); | |
/** | |
* Remove the original comment field because we've added it to the default fields | |
* using newswire_comment_form_default_fields(). If we don't do this, the comment | |
* field will appear twice. | |
*/ | |
function newswire_comment_form_defaults( $defaults ) { | |
if ( isset( $defaults[ 'comment_field' ] ) ) { | |
$defaults[ 'comment_field' ] = ''; | |
} | |
return $defaults; | |
} | |
add_filter( 'comment_form_defaults', 'newswire_comment_form_defaults', 10, 1 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment