How to disable email notification to wordpress user for approved comments?
To disable the email notification sent to WordPress users when their comment gets approved, you can use the wp_notify_postauthor
filter. By hooking into this filter, you can modify the email content or prevent it from being sent altogether. Here’s an example of how you can disable the comment approval email:
// Disable email notification for comment approval
add_filter('wp_notify_postauthor', 'disable_comment_approval_email', 10, 3);
function disable_comment_approval_email($notify, $comment_id, $comment_approved) {
if ($comment_approved == 1) {
$notify = false; // Disable the email notification
}
return $notify;
}
You can add this code to your theme’s functions.php
file or in a custom plugin file. The code hooks into the wp_notify_postauthor
filter and checks if the comment has been approved ($comment_approved == 1
). If it has, the $notify
variable is set to false
, which disables the email notification for the comment author.
By using this code, WordPress users will no longer receive an email when their comment is approved.