Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#18259 closed enhancement (worksforme)

Comment_ID() should be relative to the article

Reported by: gazpachu Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Comments Keywords:
Focuses: Cc:


After posting a comment, the anchor to the comment_ID is attached to the URL to send the user to his new comment.

This comment_ID should be relative to the article instead of showing the ID of the last comment in our wordpress DB.

i.e. I'm getting "<li id="comment-4833" ..." in an article that has two comments. And the URL is: "http://domain.ltd/post-name#comment4833", when it should be "http://domain.ltd/post-name#comment2"

The code:

<li <?php if($depth > 1) {echo comment_class('comment-replied');}  else {echo comment_class();};  ?> id="comment-<?php comment_ID() ?>">

Change History (6)

#1 @ocean90
7 years ago

  • Type changed from defect (bug) to enhancement

Marking as an enhancement because it's not a bug, it's intentionally.

Also why do you need this? If it's #2 or #9999, all the same to me. The main point is that it scrolls to the comment.

#2 @gazpachu
7 years ago

It's a matter of semantics. A #4833 ID doesn't add any meaning to the anchor/URL.


#3 @xknown
7 years ago

I do not think it worths the effort for doing this in the core. This functionality depends on how themes are coded, some of them show the trackbacks/pingbacks in the comment list, others do not.

You can do it in your theme. You have the comment_post_redirect filter to modify the url used after posting a comment.

Version 0, edited 7 years ago by xknown (next)

#4 @gazpachu
7 years ago

With comment_post_redirect I cannot add a custom ID relative to the number of comments in the post. Do you think is it possible to pass that info to the filter?

#5 @ocean90
7 years ago

  • Keywords close added; needs-patch removed

Sure, with the use of wp_count_comments.

#6 @ocean90
7 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Because it's already possible closed as works for me.

(And it seems like it works for you too, #18277)

Note: See TracTickets for help on using tickets.