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.
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:
#1 Best Overall
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.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchUse 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.
Rank #3
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.
Quick Recap
Best Value
Rank #4
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.

