• The link created by the comments_popup_link function adds #comments to the end of the permalink. On a post with comments, the anchor id is “comments” so it jumps to that anchor and works perfectly…

    However, on a post without comments, the anchor id is “respond” and it doesn’t jump to the comments area. How would I modify the function to add #respond to the permalink if no comments exist, but use #comments as the anchor tag if comments exist?

    Here’s what I’m talking about. You can see the issue by clicking links with or without comments, and the resulting jump to anchor or lack-of jump to anchor.

    https://www.nathangibbs.com

Viewing 3 replies - 1 through 3 (of 3 total)
  • This appears to be a bit of a bug in the default template, as it’s setting the anchor on the comments header, which doesn’t displayed when no comments exist.

    What I’d suggest is in the comments.php template, change the following section:

    <?php if ($comments) : ?>
    <h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to "<?php the_title(); ?>"</h3>

    to:

    <div id="comments"></div>
    <?php if ($comments) : ?>
    <h3><?php comments_number('No Responses', 'One Response', '% Responses' );?> to "<?php the_title(); ?>"</h3>

    Thread Starter Nathan

    (@njg97r)

    Worked like a charm!

    vono

    (@vono)

    Thank you so much tried lots but this finally works!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘changing anchor id depending on number of comments’ is closed to new replies.