• Resolved ourintentionalfarm

    (@ourintentionalfarm)


    I updated my theme to display the number of comments next to the date of each post using the following code: echo ‘ – ‘, get_comments_number(), ‘ comments ‘;

    In the functions.php

    How do I make this hyperlinked so it takes you directly to the comments when clicked? Right now it doesn’t link at all.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    It may be different in your theme, but in twentytwentyone, comments are in a div with the ID “comments”. So

    echo ‘ – ‘, <a href="#comments">get_comments_number(), ‘ comments ‘, '</a>';

    Moderator bcworkz

    (@bcworkz)

    Hi Intentional Farm,
    Steven’s suggestion will work on single post pages (once the syntax errors are corrected ( vs. ')). For the comment links on your home page the href value needs to include the current post’s permalink. So:
    echo ' – <a href="', esc_url( get_permalink()), '#comments">', get_comments_number(), ' comments</a>';

    Thread Starter ourintentionalfarm

    (@ourintentionalfarm)

    This community rocks! Thanks so much for you speedy suggestions. bcworkz, the home page code worked

    Thanks Steven for the single post info too.

    Appreciate you both.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Hyperlink Comment count’ is closed to new replies.