Altering the comment_form from comment-template.php
-
Howdy –
I have found tons of topics on how to add and alter fields in the comment form but I am having a hard time finding any help on altering other parts of the comment_form.
I want to add an
<a href="">
and a class “show_hide” to the “Leave a reply” title (#reply-title), and enclose the rest of the comment form in a div with the class of “slidingDiv”. The effect is to allow the user to toggle the comment form by clicking on “Leave a reply” per this jquery tutorial: https://papermashup.com/simple-jquery-showhide-div/.I was able to create the effect successfully by adding these elements to the comment_form portion of the wp-includes/comment-template.php file, but of course I DO NOT want to touch that file, so I am trying to figure out how to make this happen through my theme.
Here is the successful alteration to the code in /wp-includes/comment-template.php starting with line 1557 where i started my edits, and ending on line 1584 where I closed the div:
<h3 id="reply-title"><a href="#" class="show_hide"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?></a> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3> <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?> <?php echo $args['must_log_in']; ?> <?php do_action( 'comment_form_must_log_in_after' ); ?> <?php else : ?> <div class="slidingDiv"><form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>"> <?php do_action( 'comment_form_top' ); ?> <?php if ( is_user_logged_in() ) : ?> <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?> <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?> <?php else : ?> <?php echo $args['comment_notes_before']; ?> <?php do_action( 'comment_form_before_fields' ); foreach ( (array) $args['fields'] as $name => $field ) { echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; } do_action( 'comment_form_after_fields' ); ?> <?php endif; ?> <?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?> <?php echo $args['comment_notes_after']; ?> <p class="form-submit"> <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" /> <?php comment_id_fields( $post_id ); ?> </p> <?php do_action( 'comment_form', $post_id ); ?> </form></div>
What I added was
<a href="#" class="show_hide">
to #reply-title and<div class="slidingDiv">
around the form.So I have been trying to just include this alteration in a function and call up that function in my theme’s comments.php file, which usually uses the
<?php comment_form(); ?>
– but I am not a .php wiz, and can’t seem to figure it out.Here is a link to the test site, thought it won’t do much good, this is more of a concept to address, not really a problem that is on the site: https://www.jeannenemcek.com/beta/test-post-10/
Any help is greatly appreciated!
-Mattron
- The topic ‘Altering the comment_form from comment-template.php’ is closed to new replies.