0

I would like the create a link that point to the comment part. So when reader click on my link, it will scroll down to the place that they can leave a reply.

I have read some tutorial which teach how to create tag #id for headings in a post. However, I don't know how to do this for the comment part.

Please help! Thank you so much!

  • Edit your template, add an anchor ID just before your comment form, link to it :-) – Andy Macaulay-Brook Aug 5 '16 at 9:07
  • 1
    Thank you, but I need a little more details. @CoderSte has pointed it out. – Tai Christian Aug 16 '16 at 3:16
5

The code below should be something similar to what you're looking for

Inside the loop template you use for listing blogs (like index.php) you need something like this

<a href="<?php the_permalink(); ?>/#respond"> <!-- The blog permalink with the anchor ID after -->
    <i class="fa fa-comments-o"></i> Leave a Comment
</a>

Inside your comments.php file you could have this

<?php if ('open' == $post->comment_status) : ?>

    <div id="respond"> <!-- This is the element we are pointing to -->
        <!-- Code for comments... -->
    </div>

<?php endif; // if you delete this the sky will fall on your head ?>
| improve this answer | |
  • Thank you very much! I have inserted the class, then use function.php to create a short code for a button with the link jump to to the class. – Tai Christian Aug 16 '16 at 3:14
  • 1
    Awesome! Glad you managed to achieve what you needed to @TaiChristian – Stephen Aug 16 '16 at 7:49
0

I found a simpler solution, based on CoderSte's. Delete the

<?php the_permalink(); ?>/

from the first block of code, and then put it where you desire. That's it. The comment form already has the "respond" id, so you won't need to add the second block of code.

Removing the permalink part will prevent the site from reloading. It will simply jump to the comment section, which is the desired behavior.

This is all I added to my site. Add your button image in the tag.

<a href="#respond"><img src="" alt="" width="100" height="100" /></a>
| improve this answer | |
0

If you are inside the loop you can also use the comments_link() function to echo the link or get_comments_link() to return.

| improve this answer | |

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