Opened 9 years ago
Last modified 6 years ago
#34106 new defect (bug)
Comments should have real permalinks
Reported by: | boonebgorges | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | needs-patch |
Focuses: | Cc: |
Description
The closest think we have to comment permalinks are links like this:
example.com/my-post/comment-page-3/#comment-123
This is very fragile:
- comment-page-x is sometimes optional, as when oldest comments are displayed first, and
my-post/comments-page-1/
is the same asmy-post/
- If you change the number of comments per page, the link is no longer correct
- URL fragments (the stuff after
#
) are client-side only. Remember hashbangs? https://www.w3.org/blog/2011/05/hash-uris/ - Pagination URLs are ugly and should not be used for canonical purposes
I propose something along the following lines:
example.com/comment/123
rewrites toexample.com/?comment_id=123
WP_Query
will translatecomment_id
into the proper values forp
andcpage
redirect_canonical()
will send you toexample.com/my-post/comment-page-3/#comment-123
Comment pagination settings can change at any time, and permalinks will continue to work.
Change History (9)
#2
follow-up:
↓ 6
@
9 years ago
On the surface, this seems like a good idea to me, but I worry that the increase in urls that a page will be accessible under. Imagine a Post with 200 comments. That is now 201 urls that require DB lookups and 201 urls that a CDN needs to cache. Multiplied out, this could make bots crawling a site with a lot of comments or a lot of content more dangerous. Additionally, I don't think we can use redirect_canonical
as it stands right now, since it uses a 301 which means you can never change the page comments are on either by switching from newest to oldest, nor from switching the number of comments on a page.
This ticket was mentioned in Slack in #core by boone. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by dossy. View the logs.
9 years ago
#6
in reply to:
↑ 2
;
follow-up:
↓ 8
@
9 years ago
Replying to jorbin:
On the surface, this seems like a good idea to me, but I worry that the increase in urls that a page will be accessible under.
Occurs to me WordPress already has permalinks for comments, http://example.com/post-name/?replytocom=4159
. Could these be used as the permalink, possibly with a new rewrite along the lines of /comment/4159
?
A user linking directly to a comment may (I have no proof) be more likely to reply to the comment, the form can be displayed in the usual spot if replies are disabled.
This ticket was mentioned in Slack in #core by boone. View the logs.
9 years ago
#8
in reply to:
↑ 6
@
9 years ago
Replying to peterwilsoncc:
Occurs to me WordPress already has permalinks for comments,
http://example.com/post-name/?replytocom=4159
. Could these be used as the permalink, possibly with a new rewrite along the lines of/comment/4159
?
I believe that by under 'permalink to a comment' the reporter meant permalink to a page where the content is the comment itself, not the post + all the comments as it is now.
This would be useful for situations where the comment is crawled by remote sites; eg. it's a comment in reply to something left by a webmention and you want to make the comment available to be crawled, without the need of processing the post itself.
Right now I achieved this as:
in functions.php
<?php add_filter( 'query_vars', 'add_query_var' ); public function add_query_var($vars) { array_push($vars, 'comment' ); return $vars; } add_rewrite_endpoint ( 'comment', EP_ROOT );
in index.php
(various checking points have been stripped out for the sake of readability)
<?php global $wp; if ( array_key_exists( 'comment', $wp->query_vars ) ) { $comment_id = $wp->query_vars['comment']; $comment = get_comment($comment_id); // include comment template here exit; }
but this feels to be a hack.
#9
@
8 years ago
Was looking at this again, and had spoken to @boonebgorges at WordCamp NYC 2016 about his intent. The intent was as noted, to have a consistent permalink that would determine the pagination automatically.
I tend to be interested in the point of view of @cadeyrn where the comment permalink becomes a template option, specifically showing the comment and any of its descendants with an excerpt of the article.
While this isn't contrary to the title of the ticket, it is contrary to the intent. I wanted to raise the question of what the consequences are if comment permalink becomes a theme templated option.
Too many related tickets to list, but here are a few:
comment-page-1
is ugly)comment-page-1
is not always canonical)