1

I have a standard comment form in my theme. When user fills in the form and submits it, the comment appears in the comments list. But page does not scroll to the newly posted comment. Each comment url has an anchor:

http://example.com/post-name/#comment-3

How to make the page scroll to the newly posted comment right after post submit?

EDIT:

My comment form:

$args = array(
'fields' => apply_filters(
    'comment_form_default_fields', array(
        'author' =>'Ismingiz'.'<span style="color:red;">*</span><br>'.'<input id="author" class="form-control" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"/><br>',
    'email'  => 'Email'.'<span style="color:red;">*</span><br>'.'<input id="email" class="form-control" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .'" size="30" /><br>' ,)
),
    'comment_field' => '' . '<div class="input-group commenting-input-group input-group-lg"><textarea id="comment" class="form-control" name="comment" placeholder="Fikringiz matni..." cols="45" rows="8" aria-required="true"></textarea><br>',

'comment_notes_before' => '',
'title_reply' => '',
'class_submit'      => 'btn send-comment-button',
'label_submit'      => __( 'Yuborish' ),
'comment_notes_after' => '',
'submit_field' => '<p class="form-submit">%1$s %2$s</a></div>',
'logged_in_as' => '',
);

    comment_form($args);
?>

Comments loop:

function format_comment() {  ?>
      <div class="col-xs-2 col-md-3">  
              <?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>
            </div>
            <div class="col-xs-10 col-md-9 comment-content">
              <div class="commenter">
                <a href="<?php comment_link(); ?>"><?php comment_author(); ?></a>
                <div class="comment-date">
                  <?php comment_date(); ?>
                </div>
              </div>
              <div class="comment">
                <?php comment_text(); ?>
              </div>
            </div>

  • Sounds like javascript to run on page load. Not really a WordPress issue. You just need a scroll lib like iamdustan.com/smoothscroll and an anchor. – jgraup Nov 7 '16 at 6:58
  • But how do I set up the submit form in order to scroll to the posted comment? – Azamat Nov 7 '16 at 7:19
  • seems like your comment lack an anchor. – Mark Kaplun Nov 7 '16 at 9:54
  • <a href="<?php comment_link(); ?>"> this is the anchor link! – Azamat Nov 7 '16 at 17:55
0

It seems that the WordPress comment box isn't working properly. Or maybe you are using any comment plugin like CommentLuv then it's the Javascript problem. You can check the comment box code in the theme. The loop showing the answers should be perfect to fetch the URL of the author.

  • It is better to write this as a comment instead of answer. – Ranuka Nov 7 '16 at 8:15
  • I've edited both comment form and posts loop. Included them in the question, please take a look. – Azamat Nov 7 '16 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.