how to add thank you message after wordpress comments

Saying thank you is always good manners. In article, i have code for, add thank you message after wordpress comments after adding comments added by users. I got the same request from many of clients for adding the thank you message after putting comments after by the user who comes to site.

It was good to have this functionality. User will remember your site and you should send the thank you email to user for adding the comment to your wordpress website. For professional sites, it is very great functionality.

add thank you message after wordpress comments

In this article I will show how to add custom message after getting comments from users. For this we going use the wordpress api. WordPress filters are very useful. You can find all wordpress hooks and filters in wp-includes/default-filters.php file.

  • Method First
add_filter('comment_post_redirect', 'redirect_after_comment');
function redirect_after_comment($location){
    $newurl = substr($location, 0, strpos($location, "#comment"));
    return $newurl . '?c=y';
}

if($_GET[ 'c' ] == 'y'){
      echo 'Thank you your comemnt';
} 

Open your functions.php file from your active wordpress theme folder. copy paste the following code in that file. This is very simple trick but still it is really useful.

  • Method Second

For this method you need to create the “Thank you” page in wordpress site than open functions.php file and put following code in that file.


// Redirect to thank you post after comment
add_action('comment_post_redirect', 'redirect_to_thank_page');

function redirect_to_thank_page() {
return 'https://purabtech.in/thank-you';
}

Note: do not forget to change your URL thank you URL from code.  Above code will work in new wordpress versions.

 

 

add thank you message after wordpress comments
add thank you message after wordpress comments

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

6 thoughts on “how to add thank you message after wordpress comments”

Leave a Reply to Dan Cancel reply

Your email address will not be published.