• Resolved benipaq

    (@benipaq)


    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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter benipaq

    (@benipaq)

    Maybe it helps when I show you my WordPress for some testing.

    https://www.benjaminmurck.nl/blog

    Thread Starter benipaq

    (@benipaq)

    Somebody has an idea?

    Thread Starter benipaq

    (@benipaq)

    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);

    Thread Starter benipaq

    (@benipaq)

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Redirect after posting a comment’ is closed to new replies.