Opened 16 months ago

Last modified 16 months ago

#19893 new enhancement

get_comments_link() doesn't link properly if there are no responses

Reported by: cgrymala Owned by:
Priority: normal Milestone: Awaiting Review
Component: Comments Version:
Severity: minor Keywords: has-patch
Cc:

Description

Since the current implementation of get_comments_link() simply returns the permalink with #comments appended to the end of it, and the HTML element with an ID of comments only exists when existing comments are wrapped inside of it, it doesn't lead to anything when there are 0 comments on the post.

I've attached a patch that checks whether there are any comments on the post or not; and, if not, it appends #respond to the end of the link; otherwise it appends #comments.

Attachments (1)

comment-template.php.no-responses.get_comments_link.patch (479 bytes) - added by cgrymala 16 months ago.
get_comments_link() checks number of comments before generating link

Download all attachments as: .zip

Change History (3)

get_comments_link() checks number of comments before generating link

In the bundled themes (and I suspect most other themes as well), #respond is a descendant of #comments anyway, so this wouldn't make any difference?

I was going by the code included in wp-includes/theme-compat/comments.php, which uses #comments as an ID for the <h3> tag at the top of the comment list. That <h3> is only output when have_comments() is true (it's not wrapping anything, and doesn't even exist if there are no comments).

I realize that that file is deprecated, but if that's the way WordPress builds the comment area by default, that might be the way a lot of people are using it.

Note: See TracTickets for help on using tickets.