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: |
|
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)
Change History (3)
comment:1
solarissmoke — 16 months ago
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.

get_comments_link() checks number of comments before generating link