WordPress Comment Form Skip Link

0

Skip link (or Skip Navigation link) for comment form is really important when your entry has a lot of comments. But there’s no point in having one when your comment form is just few pixel away after the entry.

This is how you can show the skip link if the comment reach n number of comments. Example below will make the skip link appear if 1) comment status is open 2) comment count is more and equal to 4.

  1. Open your Theme’s comments.php file.
  2. After <?php if ( have_comments() ) : ?> (or anywhere you find suitable) paste these lines:
    <?php if ( comments_open() && ( 4 <= get_comments_number()) ) : ?>
    	<a href="#respond">Skip to comment form</a>
    <?php endif; ?>
    

    Example:

    <h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;<?php the_title(); ?>&#8221;</h3>
    <?php if ( comments_open() && ( 4 <= get_comments_number()) ) : ?>
    	<a href="#respond">Skip to comment form</a>
    <?php endif; ?>
    

    Don’t forget to style the codes to match your layout.

  3. Finally, make sure that an element with ID attribute respond is added or assigned. For example:
    <h3 id="respond">Leave a Reply</h3>
    

    Preferably right before the comment form.

    Using named anchor (<a name="respond" id="respond"><a/>) is outdated but still possible.

You might also like More from author