Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Last active August 17, 2023 07:36
Show Gist options
  • Save ramseyp/8812696 to your computer and use it in GitHub Desktop.
Save ramseyp/8812696 to your computer and use it in GitHub Desktop.
Different ways of customizing the WordPress comment form
<?php
// Customized the comment form fields ( not the comment text area )
add_filter('comment_form_default_fields', 'my_comment_form_args');
// Customizes the text area - you have to do this here, rather than in comment_form_default_fields
add_filter('comment_form_field_comment', 'my_comment_form_field_comment');
// Customized the comment notes above the form fields
add_filter( 'comment_form_defaults', 'my_comment_form_defaults' );
// Customize the comments title
add_filter('comment_form_defaults','my_comment_form_title');
// Show the comments count in the comments title ( Genesis Child Theme )
add_filter( 'genesis_title_comments', 'sp_genesis_title_comments' )
/**
* Customize the text prior to the comment form fields
* @param array $defaults
* @return $defaults
*/
function my_comment_form_defaults($defaults) {
$defaults['comment_notes_before'] = '<p class="comment-notes">'. __( 'Your email address will not be published. Required fields are marked','my-text-domain' ).'</p>';
return $defaults;
}
/**
* Customize the Comments form title
* @param array $args
* @return $args
*/
function my_comment_form_title ($defaults) {
$defaults['title_reply'] = __( 'Post a new comment','my-text-domain' );
return $defaults;
}
/**
* Modify the comment form input fields
* @param $args http://codex.wordpress.org/Function_Reference/comment_form
* $args['author']
* $args['email']
* $args['url']
*
* @return $args
*/
function my_comment_form_args($args) {
$args['author'] = '<p class="comment-form-author"><input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="40" tabindex="1" aria-required="true" title="'. __( 'Your Name (required)','my-text-domain' ) .'" placeholder="'. __( 'Your Name (required)','my-text-domain' ) .'" required /><!-- .comment-form-author .form-section --></p>';
$args['email'] = '<p class="comment-form-email"><input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="40" tabindex="2" aria-required="true" title="'. __( 'Email Address (required)','my-text-domain' ) .'" placeholder="'. __( 'Email Address (required)','my-text-domain' ) .'" required /><!-- .comment-form-email .form-section --></p>';
$args['url'] = '<p class="comment-form-url"><input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="40" tabindex="3" aria-required="false" title="'. __( 'Website (url)','my-text-domain' ) .'" placeholder="'. __( 'Website (url)','my-text-domain' ) .'" required /><!-- .comment-form-url .form-section --></p>';
return $args;
}
/**
* Customize the comment form comment field
* @param string $field
* @return string
*/
function my_comment_form_field_comment($field) {
$field = '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="4" title="' . __( 'Comment','my-text-domain' ) . '" placeholder="' . __( 'Comment','my-text-domain' ) . '" aria-required="true"></textarea><!-- #form-section-comment .form-section --></p>';
return $field;
}
/**
* Show how many comments there are in the commments title
* @return string $title
*/
function sp_genesis_title_comments() {
global $post;
$comment_count = wp_count_comments( $post->ID )->approved;
$title = '<p class="comments_title"><b>'. __( 'Comments','austin' ) .' ('. $comment_count .')</b></p>';
return $title;
}
@jayabalpd
Copy link

anyother comment box code available for my website please help me tnpsc exams

@BITCOIN-TIDINGS-SUPPORT
Copy link

BITCOIN-TIDINGS-SUPPORT commented Dec 2, 2021

Would you be able to enter a code that would check if the email address provided in the form is the one used and if it is not on spam blacklists?

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