Skip to main content

Remove IP addresses from WordPress comments: here's how

I'll show you how to prevent, delete or time-limit IP addresses in WordPress comments in a GDPR-compliant way (with a plugin and code).

FHFinn Hillebrandt
WordPress
Remove IP addresses from WordPress comments: here's how
Links marked with * are affiliate links. If you buy something through one of these links, we earn a commission.

First things first:

Storing commenters' IP addresses can make perfectly good sense. So please think it over before you blindly apply all the steps explained here.

I personally decided against storing them on Blogmojo.

You need a data processing agreement here

You don't need a data processing agreement here

I moderate all comments here on the blog, and I don't need IP addresses to fight spam either. On top of that, in 10 years as a blogger, nobody has ever insulted me or threatened me with violence in a comment.

So get rid of them!

Data minimization, exactly in the spirit of the GDPR. Yay!

In this article I want to show you different ways to prevent IP addresses from being stored, delete existing IPs from the database and, as a middle ground, limit how long they are kept in your WordPress database (e.g., to 7, 14, 30 or 60 days).

1. Prevent IP addresses from being stored

It's relatively easy to stop WordPress from storing commenters' IP addresses.

All you have to do is install the plugin DSGVO Tools: Kommentar-IP entfernen (“GDPR tools: remove comment IP”) or, if you prefer, add the following code to the functions.php of your child theme:

function bm_remove_ip( $comment_author_ip ) {
  return '127.0.0.1';
}
add_filter( 'pre_comment_user_ip', 'bm_remove_ip' );

This replaces the IP address of every commenter with 127.0.0.1 (commonly used for localhost).

However, this only prevents IP addresses from being stored in the future. How to remove existing IP addresses from the database is covered in the next step:

2. Delete existing IP addresses from the database

To remove existing IP addresses, you can also use the plugin DSGVO Tools: Kommentar-IP entfernen.

Go to the plugin settings (you'll find them under Kommentare > Kommentar-IP, i.e., Comments > Comment IP) and simply click the button provided:

Deleting all IP addresses in the database with the plugin DSGVO Tools: Kommentar-IP entfernen

If you're comfortable with MySQL databases and prefer to do it yourself, you can also do this with a simple command in PHPMyAdmin:

UPDATE wp_comments SET comment_author_IP = ''

3. Limit the storage period to X days

As protection against spammers, it can make sense to delete commenters' IP addresses only after a certain time (e.g., after a week).

The plugin DSGVO Tools: Kommentar-IP entfernen can do that too. In the plugin settings, simply tick the box next to Kommentar-IP-Adressen nach Zeit löschen (delete comment IP addresses after time) and set a deletion period:

Limiting how long IP addresses are stored in the database with the plugin DSGVO Tools: Kommentar-IP entfernen

Frequently asked questions

Why should I remove IP addresses from WordPress comments?
Under the GDPR, IP addresses are personal data. If you don't need them to fight spam and you moderate all comments anyway, data minimization is the safest way to stay compliant with data protection law.
How do I prevent IP addresses from being stored in the future?
Install the plugin "DSGVO Tools: Kommentar-IP entfernen" or add a short code snippet to the functions.php of your child theme that replaces the IP address with 127.0.0.1.
How do I delete existing IP addresses from the WordPress database?
Either with the plugin "DSGVO Tools: Kommentar-IP entfernen" via a button in its settings, or manually via PHPMyAdmin with the SQL command: UPDATE wp_comments SET comment_author_IP = ''
Can I store the IP address for a limited time only?
Yes, the plugin "DSGVO Tools: Kommentar-IP entfernen" has an option to delete IP addresses automatically after a set period (e.g., 7, 14 or 30 days). That way you can fight spam and still minimize data.
Are IP addresses also stored in my backups?
Yes, if you create backups, the IP addresses stay in them even if you later delete them from the live database. The actual storage period is therefore extended by the retention time of your backups.
FH

Finn Hillebrandt

SEO expert and blogger

Finn Hillebrandt is the founder of Blogmojo and an SEO expert with 15+ years of experience.

He has been an online entrepreneur since 2011 and started Blogmojo in 2016. It has grown into one of the most-visited German blogs about SEO, WordPress, and blogging, with more than 1,000,000 visitors a year.

Finn has written 140+ articles on blogging, WordPress, and SEO. The articles on blogmojo.com are English translations of them.

Follow Finn on Instagram and Threads.