Skip to content

Instantly share code, notes, and snippets.

@AlphaBlossom
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlphaBlossom/be22783594bb5db915c3 to your computer and use it in GitHub Desktop.
Save AlphaBlossom/be22783594bb5db915c3 to your computer and use it in GitHub Desktop.
Modify WordPress/Genesis Comment Form Labels
<?php
//* Do NOT include the opening php tag
/**********************************
*
* Filter Comments Form Labels
* Modify the Labels Text
* Add Font-Awesome Icons to Labels
*
* Only for Genesis HTML5 themes
* Genesis HTML5 themes use the default WordPress
* comment forms
*
* XHTML themes have to use comment_form_defaults to filter all fields
*
* @author AlphaBlossom / Tony Eppright
* @link http://www.alphablossom.com
*
************************************/
/*
*
* Filter Author, Email, and URL labels
*
*/
add_filter( 'comment_form_default_fields', 'youruniqueprefix_modify_comment_author_email_url_labels' );
function youruniqueprefix_modify_comment_author_email_url_labels( $fields ) {
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$args = wp_parse_args( $args );
if ( ! isset( $args['format'] ) )
$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
$html5 = 'html5' === $args['format'];
$fields = array(
'author' => '<p class="comment-form-author">' . '<i class="fa fa-user"></i> <label for="author">' . __( 'Your Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><i class="fa fa-envelope"></i> <label for="email">' . __( 'Your Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
'url' => '<p class="comment-form-url"><i class="fa fa-link"></i> <label for="url">' . __( 'Your Website' ) . '</label> ' .
'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);
return $fields;
}
/*
*
* Filter Comment Field label
*
*/
add_filter( 'comment_form_defaults', 'youruniqueprefix_change_comment_label' );
function youruniqueprefix_change_comment_label( $args ) {
$args['comment_field'] = '<p class="comment-form-comment"><i class="fa fa-comment"></i> <label for="comment">' . _x( 'Your Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>';
return $args;
}
/*
* Style Comments Form Labels
* and Font Awesome Icons
*
*/
.comment-respond .comment-form > p > i {
text-align: center;
width: 25px;
}
.comment-respond label {
display: inline-block;
}
.comment-respond input[type="email"],
.comment-respond input[type="text"],
.comment-respond input[type="url"] {
display: block;
width: 50%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment