Use placeholders instead of labels in comment form

Not recommended for usability reasons.

<?php
/**
* Change comment form textarea to use placeholder
*
* @since 1.0.0
* @param array $args
* @return array
*/
function ea_comment_textarea_placeholder( $args ) {
$args['comment_field'] = str_replace( 'textarea', 'textarea placeholder="comment"', $args['comment_field'] );
return $args;
}
add_filter( 'comment_form_defaults', 'ea_comment_textarea_placeholder' );
/**
* Comment Form Fields Placeholder
*
*/
function be_comment_form_fields( $fields ) {
foreach( $fields as &$field ) {
$field = str_replace( 'id="author"', 'id="author" placeholder="name*"', $field );
$field = str_replace( 'id="email"', 'id="email" placeholder="email*"', $field );
$field = str_replace( 'id="url"', 'id="url" placeholder="website"', $field );
}
return $fields;
}
add_filter( 'comment_form_default_fields', 'be_comment_form_fields' );
view raw functions.php hosted with ❤ by GitHub
.comment-respond label {
display: none;
}
view raw style.css hosted with ❤ by GitHub

comments

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk