I have been trying to add to the default WordPress comment form. I need to add placeholder=”” to each field. I can’t figure out the filter. I don’t get any errors but I don’t see the placeholder either.
After searching the posts here for an hour, I came up with this so far
function my_fields($args){
$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'" : '' );
$fields['author'] = '<input id="author" placeholder="name" name="author" type="text" value="'
. esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
return $args;
}
add_filter('comment_form', 'my_fields');
I have tried many different variations and tried returning many different things but am having no luck.
You should filter
'comment_form_default_fields'
to add theplaceholder
attribute.Sample code
Result
Some notes
label
. Screen reader users will get very angry. And it is not allowed anyway.type
attribute too. This will help your visitors more than aplaceholder
.I think you want to use this filter:
Can also focus on a specific field:
Edit, for reference:
http://codex.wordpress.org/Function_Reference/comment_form