WordPress.org

Forums

changing anchor id depending on number of comments (4 posts)

  1. Nathan
    Member
    Posted 10 years ago #

    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.

    http://www.nathangibbs.com

  2. Kafkaesqui

    Posted 10 years ago #

    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>

  3. Nathan
    Member
    Posted 10 years ago #

    Worked like a charm!

  4. vono
    Member
    Posted 9 years ago #

    Thank you so much tried lots but this finally works!

Topic Closed

This topic has been closed to new replies.

About this Topic