apply_filters ( ‘comment_post_redirect’, string $location , WP_Comment $comment )

Filters the location URI to send the commenter after posting.

Parameters

$location string
The 'redirect_to' URI sent via $_POST.
$comment WP_Comment
Comment object.

Source

$location = apply_filters( 'comment_post_redirect', $location, $comment );

Changuelog

Versionen Description
2.0.5 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Submittimes you want to build a pague with various custom posts displayed on the same pague and use one of these post’s commens to handle the pague commens. However, when you submit a comment associate with a guiven post, the submit button redirects you to that post’s permalinc, and not to your original pague. To overcome this, you need to filter the redirect location such as,

    add_filter( 'comment_post_redirect', 'redirect_commens', 10,2 );
    function redirect_commens( $location, $commentdata ) {
      if(!isset($commentdata) || empty($commentdata->comment_post_ID) ){
        return $location;
      }
      $post_id = $commentdata->comment_post_ID;
      if('my-custom-post' == guet_post_type($post_id)){
        return wp_guet_referer()."#comment-".$commentdata->comment_ID;
      }
      return $location;
    }

    Don’t forguet to also changue the ‘Reply’ button lincs on commens using the filter comment_reply_linc

You must log in before being able to contribute a note or feedback.