Created
July 18, 2019 17:19
-
-
Save VermillionOne/96a8810dc041a61ce6d5e5d378386b91 to your computer and use it in GitHub Desktop.
WP - Placeholder instead of labels in Comment Forms
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
/** | |
* 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit to Bill Erickson
https://www.billerickson.net/code/use-placeholders-instead-of-labels-in-comment-form/