How to delete followers in WordPress

How to remove IP addresses in WordPress comments (or limit how long they are stored)

First of all:

Saving the IP addresses of commentators can make perfect sense. So please think about it before blindly applying all of the steps explained here.

Personally, I decided not to save it on Blogmojo.

I moderate all the comments here on the blog and I don't need IP addresses either to fight spam. In addition, in 10 years as a blogger, I've never had a comment where someone insulted me or threatened me with violence.

So get away with it!

Data minimization in line with the GDPR. Yay!

In this article I would like to show you different ways how you can prevent the storage of IP addresses, delete existing IPs from the database and, as a middle way, limit the storage time in your WordPress database (e.g. to 7, 14, 30 or 60 days).

Danger: Before you change anything in the code or in your database, please make a backup!

1. Prevent the storage of IP addresses

It is relatively easy to prevent the storage of the IP address of commentators in WordPress.

To do this, simply install the GDPR Tools plug-in: remove comment IP or optionally 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 all commentators with 127.0.0.1 (usually used for the localhost).

However, this only prevents the future storage of IP addresses. In the next step you will find out how to remove existing IP addresses from the database:

2. Delete existing IP addresses from the database

To remove existing IP addresses, you can also use the GDPR Tools: Remove Comment IP plug-in.

To do this, go to the plugin settings (to be found under Comments> Comment IP) and simply click on the button provided:

If you are confident in handling MySQL databases and prefer to lend a hand yourself, you can do this with a simple command in PHPMyAdmin implement:

UPDATE wp_comments SET comment_author_IP = ''
Note: If you use a different database prefix than, you should replace it in the command accordingly!

3. Limit the storage period to X days

To protect against spammers, it can make sense to delete commentators' IP addresses only after a certain period of time (e.g. after a week).

This is also possible with the GDPR Tools: Remove Comment IP plug-in. To do this, simply check the box in the plugin settings Delete comment IP addresses after a time and define a deletion period:

Note: If you make backups of your WordPress installation, this also extends the actual storage time of the IP addresses, as these are still available in your backups even after deletion.