Remove IP Addresses From Comment Notification Emails
Strips commenters' IP addresses and host names from the new comment and moderation emails WordPress sends to authors and administrators, so personal data does not pile up in inboxes.
Opens WPIDE on
Code
$wpide_strip_comment_ip = function ( $message, $comment_id ) {
$comment = get_comment( $comment_id );
if ( ! $comment ) {
return $message;
}
// English wording first, then any remaining copy of the raw address (for translated emails).
$message = preg_replace( '/\s*\(IP address: [^)]*\)/', '', $message );
if ( $comment->comment_author_IP ) {
$message = str_replace( $comment->comment_author_IP, '[hidden]', $message );
}
return $message;
};
add_filter( 'comment_notification_text', $wpide_strip_comment_ip, 20, 2 );
add_filter( 'comment_moderation_text', $wpide_strip_comment_ip, 20, 2 );
Notes
The IP address is still visible in the dashboard for administrators if you store it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.