Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created October 22, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/c93b9a45d808f7274bf6 to your computer and use it in GitHub Desktop.
Save billerickson/c93b9a45d808f7274bf6 to your computer and use it in GitHub Desktop.
<?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' );
.comment-respond label {
display: none;
}
@KostasNi
Copy link

Wouldn't be better to add the .screen-reader-text class to the labels instead of display: none for accessibility?

Another use of .screen-reader-text is to hide labels in forms. Search forms are a common place where designers use placeholders and image buttons to convey the purpose of the form. Adding a label that’s available to screen readers make the form usable for screen reader users, without altering the design.
-Hiding text for screen readers with WordPress Core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment