Here's how to customize the Genesis Comment form.
[php]add_filter('genesis_comment_form_args', 'custom_genesis_comment_form_args');
/**
* Modify comments
*/
function custom_genesis_comment_form_args($args) {
$args = array (
'title_reply' => __( 'Leave a Comment', 'genesis' ), //default='Speak Your Mind'; WordPress deafult: __( 'Leave a Reply' )
'label_submit' => __( 'Submit Comment', 'genesis' ), //default='Post Comment'
'title_reply_to' => __( 'Reply Title', 'genesis' ), //Default: __( 'Leave a Reply to %s' )
'cancel_reply_link' => __( 'Cancel', 'genesis' ) //Default: __( 'Cancel reply' )
);
return $args;
}[/php]
To Change the Reply Link Text or the Login to Comment Text, add this to your functions.php, which is largely borrowed from WordPress core so it maintains the same functionality.
[php]add_filter('comment_reply_link', 'custom_comment_reply_link');
function custom_comment_reply_link($args) {
global $user_ID;
$args = array(
'reply_text' => __('Debate'), // WordPress/Genesis Default: Reply
'login_text' => __('Please Log in First')); // WordPress/Genesis Default: Log in to leave a comment
$defaults = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'),
'login_text' => __('Log in to Reply'), 'depth' => 0, 'before' => '', 'after' => '');
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
$comment = get_comment($comment);
if ( empty($post) )
$post = $comment->comment_post_ID;
$post = get_post($post);
if ( !comments_open($post->ID) )
return false;
$link = '';
if ( get_option('comment_registration') && !$user_ID )
$link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
else
$link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm("$add_below-$comment->comment_ID", "$comment->comment_ID", "$respond_id", "$post->ID")'>$reply_text</a>";
return $link;
}[/php]
You can edit the comment form (to add WILL NOTE BE PUBLISHED beside the Email, etc.) with this code in your [I]functions.php[/I] file.
[php]add_filter('genesis_comment_form_args','custom_email_note');
function custom_email_note() {
$args = array(
'fields' => array(
'author' => '<p class="comment-form-author">' .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" tabindex="1"' . $aria_req . ' />' .
'<label for="author">' . __( 'Name', 'genesis' ) . '</label> ' .
( $req ? '<span class="required">*</span>' : '' ) .
'</p><!-- #form-section-author .form-section -->',
'email' => '<p class="comment-form-email">' .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" tabindex="2"' . $aria_req . ' />' .
'<label for="email">' . __( 'Email: Not Published', 'genesis' ) . '</label> ' .
( $req ? '<span class="required">*</span>' : '' ) .
'</p><!-- #form-section-email .form-section -->',
'url' => '<p class="comment-form-url">' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" tabindex="3" />' .
'<label for="url">' . __( 'Website', 'genesis' ) . '</label>' .
'</p><!-- #form-section-url .form-section -->'
),
'comment_field' => '<p class="comment-form-comment">' .
'<textarea id="comment" name="comment" cols="45" rows="8" tabindex="4" aria-required="true"></textarea>' .
'</p><!-- #form-section-comment .form-section -->',
'title_reply' => __( 'Speak Your Mind', 'genesis' ),
'comment_notes_before' => '',
'comment_notes_after' => '',
);
return $args;
}[/php]
Rob Cubbon says
Thanks for this, I used it to add “real name, please no keywords” after the Name label in the comment form.
Do these commands in the functions.php affect page loading times or would that be negligible?
wpsmith says
Hello Rob,
The loading time effect would be negligible.
Thanks,
Riyaz says
The issue with the Genesis comment form is that once you enter your comments and press the tab key, you are taken to top of the page instead of the submit button. I guess tabindex is not set. Is there an easy way to fix this?
David M says
I’m wondering how I can add tabindex=5 to the submit comment button. I tab through text fields and it works fine from author to email to URL to comment, but when I tab to submit it takes me to the top of the page.
Travis Smith says
Currently, this is not possible in WordPress. I’ve added a ticket in WordPress to see if this can be done.
David M says
It’s possible, Travis. The theme I’m currently using allows you to tab from Name to Email to Website to Text box to Submit Comment. You can check out the theme I’m currently using to test it yourself. Just click on my name.
The submit button has this inline: input id=”submit” type=”submit” value=”Submit Comment” tabindex=”5″ name=”submit”
The problem with Genesis, or I should say my problem anyway, is that I can’t find the comment form submit button. The Name, Email, Website and Text field are tabindexed 1, 2, 3, and 4. Here’s the text area:
textarea id=”comment” name=”comment” cols=”45″ rows=”8″ tabindex=”4″ aria-required=”true”
Travis Smith says
I apologize… technically ANYTHING is possible. However, if you want to use the comment system WordPress provides itself and not re-write it, then it is not possible (to do it within the WP confines) at this time. What theme are you using that does this?
David M says
It’s a Yootheme template. It just seems odds to me that this wouldn’t be easily done. Obviously WordPress sees the value in tabbing between name, email, website and text box. Who are the people who are going to use that? The same ones who then tab to the submit button.
Out of curiosity, could I replace the genesis/lib/structure/comments.php file with the one I’m currently using? Genesis is unusable to me if I can’t complete this simple task. That would be unfortunate as I really like the framework.
David M says
I figured it out. Just remove tabindex=”1″, tabindex=”2″ tabindex=”3″, tabindex=”4″
Affan Ruslan says
I tried the second code, ang got an error.
weblarus says
You should merge your args with the default arguments.
function my_comment_form_args( $defaults ) {
…
$args = wp_parse_args( $args, $defaults );
return $args;
}
Travis Smith says
Yes, I could but I believe I used all possible args in the example so it would be redundant.
Brian Steck says
Travis and Weblarus, I’m not sure if it would be redundant? Using this code, I’m not getting a “submit button. Any thoughts?
Jo Waltham says
Is it possible to change the submit button? I’ve been advised to track comments in my Google Analytics and I need to add
onclick=”javascript: pageTracker._trackPageview(’/goal/wordpress.html’);”
to it.
I can’t see any way without hacking the core code.
Thanks
Josh Stauffer says
Thanks for providing the code snippets above. I did have trouble getting the first code snippet working. Perhaps additional array elements have been added since this was first published.
Anyway, all I wanted to change was the ‘Speak Your Mind’ text. Here’s how I went about it with your original code:
add_filter( ‘genesis_comment_form_args’, ‘custom_genesis_comment_form_args’ );
/** Modify comments */
function custom_genesis_comment_form_args( $args ) {
$args[‘title_reply’] = __( ‘Have a Comment?’, ‘genesis’ );
return $args;
}
Tushar Thakur says
There is a bit problem in your second code. You forgot define the label for post comment button, So if anyone only put this code in functions.php then reply button will become a small with no text on it. 🙂
Take a look.
Matt Vaden says
Thank you very much for providing this code and helping to clarify the WP Codex concerning the WP/Genesis comment form. I have used your code to help me:
1. Remove the URL field.
2. Add JavaScript to the name and email field.
3. Add a “comment policy” and “user encouragement” messages via the ‘comment_notes_before’ => ”, and ‘comment_notes_after’ => ”, fields.
4. …and finally, I added some additional CSS classes to assist me in styling some of the HTML elements.
Anyway, thank you again for this great tutorial. I really appreciate it because it helped me ‘accomplish my mission’ to customize my WP comment form.
Regards,
Matt Vaden
vajrasar says
I want to have comment system where nothing should show up at first instead of “Comment” box. As soon as user writes comment and press “Post Comment” – A pop up box should appear asking him to login via FB, Twitter or Register. Is it possible?
Something like – Example
I have been all over the web, but no such stuff. Thanks for the help.
Am using Genesis with News Child Theme.
Rayno says
Hi, how to change “Reply” text?