Redirect users after leaving a comment

When you start publishing articles, you will want people to comment on them, of course. We have already shown you how to allow people to comment without providing their email addresses, you can allow them to use more HTML tags in their comments and much more. You can automatically remove links from comments and much more, but in today’s article, we’re about to show you how to redirect a user after submitting a comment.

This function might come in handy for you if in certain situations. For example, you might want to create a custom “thank you” page for a giveaway you’re organizing. So, when visitors participate in a giveaway by leaving a comment, you can easily redirect them to that “thank you” page where you can provide additional information about prizes.

There are actually tons of different reasons you might have for redirecting a user after leaving a comment, so without further ado, here’s what you need to do in order to automatize the process.

Redirect user after submitting a comment:

  1. Open functions.php file
  2. Copy and paste this code in the file:
  3. function redirect_after_comment(){
    add_filter('comment_post_redirect', 'redirect_after_comment');
  4. Change the name of the page on the 2nd line
  5. Save changes

That’s it. You can now go on and test the function. Open any of your posts and leave a comment. If you have done everything correctly, you should end up on http:/ page or the one specified on the second line of your code.

Thank you page

Now you have a job of creating that page more personal. Don’t forget to thank people for commenting but also don’t forget that you want your visitors to stay on the site and continue on browsing. A good idea might be to add a list of your recent or most popular posts, or maybe even better to list all related posts which might be of interest to a commenter.

If you have a mailing list, this is a good place to offer a subscription to it.

While this function offers easy and a quick way of redirecting users after they leave a comment, you may be interested in a plugin which will give you with some additional features.

Start Blog Book


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *