Post comment form customization
Post comment forms are not the easiest to customize. Thankfully, GeneratePress provides a few functions to facilitate the process.
Resize author comment avatar
The following snippet will increase the size of the author comment avatar:
add_filter( 'generate_comment_avatar_size', function() { return 100; // The size in pixels. This would be 100 x 100. } );
Rename comment title
The following snippet will rename the comment title from [comment count] thoughts on...
to Comments
(see next screenshot):
add_filter( 'generate_comment_form_title', function() { return 'Comments'; } );
Add content below comment title
This snippet will add content below the post title:
add_action( 'generate_below_comments_title','generate_comments_email_message' ); function generate_comments_email_message() { ?> <p class="total-comments">Total Comments: ( <?php comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1', 'generatepress' ), __( '%', 'generatepress' ) ); ?> ) </p> <?php }
Add placeholder text in comment textarea field
This snippet will add a placeholder text in comment textarea field (see next screenshot):
function placeholder_comment_form_field($fields) { $replace_comment = __('Comment *', 'generatepress'); $fields['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" placeholder="'.$replace_comment.'" aria-required="true"></textarea></p>'; return $fields; } add_filter( 'comment_form_defaults', 'placeholder_comment_form_field', 20 );
Add text after Leave Comment title
This snippet will insert content after the Leave Comment
title:
Add comment URL label without removing the placeholder
This snippet will add a URL label without removing the placeholder:
add_filter( 'comment_form_default_fields', function( $fields ) { $commenter = wp_get_current_commenter(); $fields['url'] = sprintf( '<label for="url">%1$s</label><input placeholder="%1$s" id="url" name="url" type="url" value="%2$s" size="30" />', esc_html__( 'Website', 'generatepress' ), esc_attr( $commenter['comment_author_url'] ) ); return $fields; }, 20 );
That’s all for now, I will updating this post with new related code snippets in the future!