Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To change where visitors land after submitting a WordPress comment, use the comment_post_redirect filter. Return the destination URL from its callback; WordPress applies it during the comment-submission flow and performs the redirect.

Send commenters to a thank-you page

Add the filter in a small site-specific plugin or in your child theme’s functions.php. A site-specific plugin keeps the behavior in place if you change themes. Replace /thank-you/ with the path to an existing page on your site.

add_filter( 'comment_post_redirect', 'site_redirect_after_comment', 10, 2 );

function site_redirect_after_comment( $location, $comment ) {
    return home_url( '/thank-you/' );
}

The filter callback receives the destination WordPress would otherwise use and a WP_Comment object. If the callback does not need the comment, it can accept only $location. Return the URL from the callback; do not call wp_redirect() there. WordPress’s reference describes the hook as filtering the location URI sent to the commenter: comment_post_redirect.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Return the commenter to the post and new comment

To send the visitor back to the post they commented on and point the browser to the new comment, build the destination from the comment object:

add_filter( 'comment_post_redirect', 'site_return_to_commented_post', 10, 2 );

function site_return_to_commented_post( $location, $comment ) {
    return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
}

This is a deliberate local destination tied to the submitted comment. Avoid choosing a destination from untrusted request data: WordPress ultimately uses wp_safe_redirect(), which checks absolute URLs against allowed hosts and falls back to a local URL when a destination is unsafe. See the wp_safe_redirect() reference.

Decide whether to preserve WordPress’s default destination

During a normal comment submission, wp-comments-post.php uses a posted redirect_to value when present; otherwise it builds a link to the comment. If a comment is awaiting moderation and the commenter has not consented to comment cookies, core can add query arguments used to show a moderation message. WordPress applies comment_post_redirect to that location, calls wp_safe_redirect(), and exits. The flow is visible in WordPress core’s wp-comments-post.php.

Returning a fixed thank-you URL replaces the existing destination, so it can discard the comment anchor and moderation-related query arguments. If those matter to your site, account for them when deciding how to customize the destination rather than replacing the location blindly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use the redirect filter, not the comment action

comment_post_redirect is the filter for choosing the location used after comment submission. The comment_post action fires just after a comment is inserted into the database; it is intended for side effects such as notifications, not selecting the redirect destination. See the comment_post action reference.

WordPress’s comment flow exits after calling wp_safe_redirect(). That function does not exit by itself, so if you implement a separate redirect handler rather than using this core flow, follow the function documentation and exit after a successful redirect.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.