WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 10 2011

How to Customize the Genesis Comment Form

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]

Written by Travis Smith · Categorized: Genesis, Tutorials

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Rob Cubbon says

    July 3, 2011 at 10:06 am

    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?

    Reply
    • wpsmith says

      July 3, 2011 at 7:49 pm

      Hello Rob,

      The loading time effect would be negligible.

      Thanks,

      Reply
  2. Riyaz says

    September 11, 2011 at 1:09 pm

    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?

    Reply
  3. David M says

    January 22, 2012 at 2:47 pm

    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.

    Reply
    • Travis Smith says

      January 30, 2012 at 10:56 am

      Currently, this is not possible in WordPress. I’ve added a ticket in WordPress to see if this can be done.

      Reply
      • David M says

        February 6, 2012 at 11:20 am

        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”

        Reply
        • Travis Smith says

          February 6, 2012 at 11:32 am

          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?

          Reply
          • David M says

            February 6, 2012 at 11:40 am

            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

            February 6, 2012 at 11:50 am

            I figured it out. Just remove tabindex=”1″, tabindex=”2″ tabindex=”3″, tabindex=”4″

  4. Affan Ruslan says

    August 22, 2012 at 2:31 pm

    I tried the second code, ang got an error.

    Reply
    • weblarus says

      September 11, 2012 at 3:55 am

      You should merge your args with the default arguments.

      function my_comment_form_args( $defaults ) {
      …
      $args = wp_parse_args( $args, $defaults );
      return $args;
      }

      Reply
      • Travis Smith says

        September 12, 2012 at 5:51 am

        Yes, I could but I believe I used all possible args in the example so it would be redundant.

        Reply
        • Brian Steck says

          October 17, 2012 at 7:04 pm

          Travis and Weblarus, I’m not sure if it would be redundant? Using this code, I’m not getting a “submit button. Any thoughts?

          Reply
  5. Jo Waltham says

    September 25, 2012 at 12:26 pm

    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

    Reply
  6. Josh Stauffer says

    October 14, 2012 at 2:47 pm

    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;
    }

    Reply
  7. Tushar Thakur says

    October 18, 2012 at 4:44 am

    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.

    Reply
  8. Matt Vaden says

    November 28, 2012 at 12:48 am

    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

    Reply
  9. vajrasar says

    January 21, 2013 at 6:59 am

    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.

    Reply
  10. Rayno says

    July 2, 2013 at 5:45 am

    Hi, how to change “Reply” text?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in