Redirect to custom URL after adding Comment – WordPress

A function that helps you to redirect to any custom page after posting WordPress comment. WordPress provides many filters to do this custom redirection. Few of tricks are explaining in this article as below:

In WordPress, You can do this thing using 2 ways:

  • using hidden field in comment form
  • using action hook

Before processing next, You assure that you have already created custom page (Here we call it THANK YOU page). You can easily add this page by following way :
Go to your WordPress Dashboard -> Pages -> Add New
and put some interesting content there.

After adding page, You have to get this page URL (I assume this page URL like below: )

Method-1: Using hidden field in comment form

This is very easy and quick way. Open your comments.php file in the theme folder (/wp-content/themes/your-theme), you’ll find something looks like:

You only need to add line as below:

As you see the URL of Thank you page is used as the value of the hidden field.

Method-2: Using action hook

In this method, we’ll use the comment_post_redirect action hook. Open your functions.php file in theme folder and insert these lines:


It’s enough for this article. Stay connect for some new tricks.

Leave a Reply

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