• Heya, I’m using the following code to display the comments and comment form:

    <?php comments_template( '', true ); ?>
    <?php comment_form(); ?>

    But I can figure out where I can get the default code to build my template for this form off of. Nor do I know how to create the template itself. Meaning; do I create comment-template.php and WordPress knows how to overwrite that or what?

    I have reviewed the codex but I am still confused. Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter Spencer Hill

    (@ws5f3dj7)

    Bumping this to the top of the forum since I haven’t received any replies.

    But I can figure out where I can get the default code to build my template for this form off of.

    try to use comments.php of twenty ten.
    (if you do, make sure to remove the callback from
    wp_list_comments( array( 'callback' => 'twentyten_comment' ) );)

    for modifying the comment form, see:
    https://codex.www.ads-software.com/Function_Reference/comment_form

    Thread Starter Spencer Hill

    (@ws5f3dj7)

    Thanks for the reply. Comments.php appears to be different than the function that calls whatever file generates comment_form(). Comments.php being just the comments themselves not the file I’m trying to modify…

    the function ‘comment_form()’ builds the actual form, see:
    https://codex.www.ads-software.com/Function_Reference/comment_form

    not very intuitive; however, this seems to be part of more recent themes.

    if you want to have a ‘handmade’ form, you probably have to go back to older themes, such as the former default theme https://www.ads-software.com/extend/themes/default, where such a form is part of comments.php

    You can actually build a pretty decent custom comment form by using the arguments to comment_form and some CSS.

    The comment form is in the wp-includes/comment-template.php file. If you want to change the form you can change there. (Make sure you know what you are doing.) or else you can replace the <?php comment_form(); ?> and replace it with the this code https://codex.www.ads-software.com/Styling_Theme_Forms#The_Comments_Form

    then you can do the changes to the code. Hope this is the answer you were looking for

    I wouldn’t recommend what anujasha9 said, it’s pretty dangerous to change the source code, this is what I did for mine:

    <?php $comment_args = array( 'fields' => apply_filters( 'comment_form_default_fields', array(
                'author' => '' .
                            '<label for="author">' . __( 'Your Name:' ) . '</label> ' .
                            ( $req ? '<span class="required">*</span>' : '' ) .
                            '<input id="author" name="author" type="text" value="' .
                            esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
                            '<!-- #form-section-author .form-section -->',
                'email'  => '' .
                            '<label for="email">' . __( 'Your Email:' ) . '</label> ' .
                            ( $req ? '<span class="required">*</span>' : '' ) .
                            '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />' .
                    '<!-- #form-section-email .form-section -->',
                'url'    => '' ) ),
                'comment_field' => '' .
                            '<label for="comment">' . __( 'Comment:' ) . '</label>' .
                            '<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
                            '<!-- #form-section-comment .form-section -->',
                'comment_notes_after' => '',
            );
            comment_form($comment_args); ?>

    Or what twentyten does and create your function inside the functions.php file, look up function function twentyten_comment to see what I mean, otherwise here’s another good tutorial to read.

    it’s pretty dangerous to change the source code

    Loudly seconded. ral_ani’s suggestions are a far better solution.

    The comment form is in the wp-includes/comment-template.php file. If you want to change the form you can change there.

    This is a terrible suggestion.

    Never, never, never do this!!! Do not modify core WordPress files.

    The comment_form() function is hooked to within inches of its life. It is one of the most customizable functions in all of WordPress. Use the action and filter hooks it provides, if you need to modify it.

    Thread Starter Spencer Hill

    (@ws5f3dj7)

    Thank you for the feedback everyone. As a developer I would, obviously, never modify core files unless I was in an emergency (time sensitive situation) and had no alternative. But even then I would seek the proper solution immediately after and undo those changes since modify the core files of well known platform would create frustration for the common developer.

    Chip, I believe I understand filter hooks but I don’t have much experience actually utilizing filter hooks (that I’m conscious of). Could you give an example of how I would use one in this case?

    Fundamentally I just want to rearrange how this comment input area is laid out and the labels/text beside each input and inside the button.

    Thank you again everyone!

    Thread Starter Spencer Hill

    (@ws5f3dj7)

    ral_ani, thanks for your suggestions and example. That might actually be what I’m looking for. I’m trying to follow WordPress best practices as much as possible so is the consensus that ral_ani’s solution would be a fitting solution?

    Thank you!

    Could you give an example of how I would use one in this case?

    Sure!

    Say you wanted to add a custom field, for a CAPTCHA. You would put the markup for it inside of a function, and then hook in that function, e.g.:

    function mytheme_spam_protection() {
       // Some HTML form markup for a CAPTCHA
    }
    add_action( 'comment_form_after_fields' , 'mytheme_spam_protection' );

    ral_ani, thanks for your suggestions and example. That might actually be what I’m looking for.

    Yes, that is a great example. That argument array is fairly powerful all on its own.

    Thank you Rali-ani for the link to the tutorial – i have needded help with that.

    But I have one question – is it better to use the

    <?php comment_form( $args, $post_id ); ?>

    rather that putting the old way which is what that tutorial shows??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How do I overwrite the comments template? Need help…’ is closed to new replies.