• I want to change the redirect behavior when I post a comment. I want it to be redirected to the original url without the additional comment information tacked on to the url.

    For example.
    The current url before comment submission is
    https://theviolent.net/grunge/page-1
    The current behavior adds misc. info to the end as seen below
    https://theviolent.net/grunge/page-1/comment-page-1/#comment-29
    My desired behavior is to have the starting and ending url to be the same without the misc info added. I’d like to do this without having to modify the core wordpress files.

    Thanks for the help!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter giant slayer

    (@giant-slayer)

    I found the code within the wordpress core file wp-comments-post.php.

    $location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
    $location = apply_filters('comment_post_redirect', $location, $comment);
    
    wp_redirect($location);

    I see where it adds the additional information to the url. I can modify this file to do what I want, but I’d rather not modify the wordpress core. So I’m not sure how to go about doing what I want to do.

    Thanks for your help!!

    Thread Starter giant slayer

    (@giant-slayer)

    I found this piece of code
    <input type="hidden" name="redirect_to" value="<?php echo convert_chars($_SERVER['REQUEST_URI']); ?>"/>
    It partially does what I want by eliminating “/comment-page-1/” from the url.

    But it is still appending the #comment-{comment#} to the end of the url.

    Any ideas on how to remove that portion as well?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I modify the comment url behavior without modifying wp-comments-post.php?’ is closed to new replies.