Created
May 5, 2017 10:57
-
-
Save kirandash/74fd9b9c3f6ebd0000bb2317c0e8be60 to your computer and use it in GitHub Desktop.
Modify comments form WordPress
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
<?php | |
add_filter( 'comment_form_default_fields', 'wpse_62742_comment_placeholders' ); | |
/** | |
* Change default fields, add placeholder and change type attributes. | |
* | |
* @param array $fields | |
* @return array | |
*/ | |
function wpse_62742_comment_placeholders( $fields ) | |
{ | |
$fields['author'] = str_replace( | |
'<input', | |
'<input placeholder="Name*"', | |
$fields['author'] | |
); | |
$fields['email'] = str_replace( | |
'<input id="email" name="email" type="email"', | |
/* We use a proper type attribute to make use of the browser’s | |
* validation, and to get the matching keyboard on smartphones. | |
*/ | |
'<input type="email" placeholder="Email*" id="email" name="email"', | |
$fields['email'] | |
); | |
$fields['url'] = str_replace( | |
'<input id="url" name="url" type="url"', | |
// Again: a better 'type' attribute value. | |
'<input placeholder="Website" id="url" name="url" type="url"', | |
$fields['url'] | |
); | |
return $fields; | |
} | |
/** | |
* Changing the view for user viewing comment form | |
*/ | |
function alter_comments_defaults( $defaults ) { | |
global $post; | |
$defaults = array( | |
'title_reply' => '<a name="add-a-comment"></a>' . __( 'leave a comment', 'thirdrock' ) . ' ', | |
'cancel_reply_link' => __( 'cancel#a#comment', 'thirdrock' ), | |
'label_submit' => __( 'submit', 'thirdrock' ), | |
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . | |
_x( 'comment#box#label', 'thirdrock' ) . | |
' * </label><textarea id="comment" name="comment" cols="45" rows="4" aria-required="true" placeholder="Comment"></textarea></p>', | |
); | |
return $defaults; | |
} | |
add_filter( 'comment_form_defaults', 'alter_comments_defaults' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment