Title: comment_post_redirect
Published: April 25, 2014
Last modified: February 24, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#wp--skip-link--target)

Filters the location URI to send the commenter after posting.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#parameters)󠁿

 `$location`string

The `'redirect_to'` URI sent via $_POST.

`$comment`[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)

Comment object.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-comments-post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-comments-post.php#L78)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-comments-post.php#L78-L78)

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.5](https://developer.wordpress.org/reference/since/2.0.5/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/comment_post_redirect/?output_format=md#comment-content-2088)
 2.   [Aurovrata Venet](https://profiles.wordpress.org/aurovrata/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/comment_post_redirect/#comment-2088)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_post_redirect%2F%23comment-2088)
    Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_post_redirect%2F%23comment-2088)
 4. Sometimes you want to build a page with various custom posts displayed on the same
    page and use one of these post’s comments to handle the page comments. However,
    when you submit a comment associate with a given post, the submit button redirects
    you to that post’s permalink, and not to your original page. To overcome this, 
    you need to filter the redirect location such as,
 5.     ```php
        add_filter( 'comment_post_redirect', 'redirect_comments', 10,2 );
        function redirect_comments( $location, $commentdata ) {
          if(!isset($commentdata) || empty($commentdata->comment_post_ID) ){
            return $location;
          }
          $post_id = $commentdata->comment_post_ID;
          if('my-custom-post' == get_post_type($post_id)){
            return wp_get_referer()."#comment-".$commentdata->comment_ID;
          }
          return $location;
        }
        ```
    
 6. Don’t forget to also change the ‘Reply’ button links on comments using the filter`
    comment_reply_link`
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_post_redirect%2F%3Freplytocom%3D2088%23feedback-editor-2088)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_post_redirect%2F)
before being able to contribute a note or feedback.