Correct Redirection after Posting a Comment
Separating comments and trackbacks is one of the first things many WordPress users would do when they have a fresh WordPress installation. The benefit is clear, but is there any catch? Just post a new comment when separation is active and paged comments is enabled, you will be magically redirected to a page with no comments rather than pingbacks/trackbacks.
Now I have good news and bad news for you. The good news is, ‘magically’ can actually mean ‘logically’ sometimes, and the bad news is, to fix this you will have to, as far as I know, hack a core file. That core file, as you might have guessed, can be no other than
So, let’s have a good look at the guilty file, shall we? Scroll down to line 100 and you should see this:
$location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
What’s causing the issue is merely this function:
It uses an interesting argument, ‘type’, and according to the codex page, that argument allows you to specify the type of comment used in generating the redirection URL, i.e. the URL to the comment page a visitor will land on after posting a comment.
Basically, when you use
get_comment_link($comment_id) without the ‘type’ argument you are telling WordPress to redirect visitors to a page that is expected to have comments and pingbacks all in one place. When you separate pingbacks from real comments and list all of them under your blog post, you are obviously need less comment pages than needed.
For example you have a popular post with 200 comments in total of which 20 are pingbacks, and you choose to show just 100 comments per page. When someone posts the 201st comment, WordPress will normally redirect him/her to
http://example.com/this-is-a-post/comment-page-3/#comment-201 (assuming that all comments are top-level).
The problem is you will have only 181 real comments (180 plus the newly submitted one) which is less than 200, which means no real comment should be shown for
To tell the truth, fixing the issue is much easier than explaining it, so I think you might have figured out the workaround already. Just change the 100th line of
wp-comments-post.php to this:
$location = empty($_POST['redirect_to']) ? get_comment_link($comment_id, array('type' => 'comment')) : $_POST['redirect_to'] . '#comment-' . $comment_id;
and… Voila, the redirection is now correct!
Remember to make this change to the guilty file whenever WordPress is updated, though. It’s not a fun task, I know, but until there’s a hook for that function, this is the only solution I can come up with. If someone has a better idea, please comment below, thanks!