Maybe it helps when I show you my WordPress for some testing.
http://www.benjaminmurck.nl/blog
I found it out myself.
What to do:
Find
$location = apply_filters(‘comment_post_redirect’, $location, $comment);
Change it to
$location = apply_filters(‘comment_post_redirect’, $redirect_to);
Add above
$redirect_to = ‘index.php’;
So you will get
$redirect_to = ‘index.php’;
$location = empty($_POST[‘redirect_to’]) ? get_comment_link($comment_id) : $_POST[‘redirect_to’] . ‘#comment-‘ . $comment_id;
$location = apply_filters(‘comment_post_redirect’, $redirect_to);
You will find this code in wp-comments-post.php
I had a similar problem and ended up here. I didn’t want to edit the wp-comments-post.php because it would change the redirect behavior everywhere comments were used.
This inspired me to work with a hidden redirect_to field in a new index-comments.php file because I wanted this redirect only for a user commenting on the home page. I then called it like this in my index.php
<?php comments_template("/index-comments.php"); of course after setting the <?php $withcomments = 1 ?> way before the loop.
Thanks for answering yourself. It surely helped me.
Thanks Ben, works beautifully.
(@benipaq)
16 years, 6 months ago
Hello all,
First of all; I did my research about this question so I am not just a lazy bloke to post my question here π
Here we go;
How can I redirect to my index after posting a comment/hitting the ‘submit comment’ button?
Hopefully there is somebody who can help me out!
Greets,
Benjamin