Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Stop Storing IP Address in WordPress Comments

After reading our article on how to allow anonymous comments, one of our readers asked us if it was possible to stop storing IP address in WordPress comments. Some site owners may want to do that to protect privacy of their users. In this article, we will show you how to stop storing IP address in WordPress comments.

Comment Privacy in WordPress

Pros and Cons of Not Storing IP Address in WordPress Comments

By default, WordPress logs and stores IP addresses of users leaving comments on your website. These IP addresses are permanently stored in your database.

The reason for storing IP addresses with each comment is to help site owners combat with unwanted comments or spam. Plugins like Akismet can block comments from IP addresses known to be exploited by spammers.

Unless your users are using a VPN service, their real IP addresses can still be found in your site logs. Most WordPress hosting providers keep an access log of all visitors to your website for a limited period of time.

On the other hand by not storing IP address in WordPress comments, you can improve privacy of commenters on your website. They may feel more confident about expressing their opinions knowing that your site doesn’t store IP addresses with comments.

Method 1: Stop Storing IP Addresses in Comments with Plugin

This method is easier and recommended for new websites and beginners.

First thing you need to do is install and activate the Remove IP plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Once activated, the plugin will replace user IP with 127.0.0.1, which is an IP address typically used by localhost.

The plugin will not delete IP addresses stored with older comments. If you have older comments with IP addresses stored with them, then you may want to delete those IP addresses as well. We will show you how to do that later in this article.

Method 2: Manually Stop Storing IP Addresses with WordPress Comments

If you are comfortable pasting code snippets in WordPress, then you should use this method instead.

Simply add this code to your theme’s functions.php file or a site-specific plugin.

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

This is basically the same code used by the plugin we mentioned in the first method. However, instead of storing 127.0.0.1, it leaves the IP field blank.

Remove IP Address From Old Comments

Regardless of which method you use to stop storing comments IP, old comments on your WordPress site will always have IP addresses stored with them.

If you have old comments on your site, then you may want to remove IP addresses from those comments.

We will show you how to do that by running a MySQL query on your WordPress database. It is really important to make sure that you have the most recent WordPress database backup.

Next you need to login to your WordPress hosting control panel and look for phpMyAdmin.

Make sure that you have selected your WordPress database by clicking on the database name in the column on your left hand. After that you need to click on the SQL menu.

Removing IP address from old comments in WordPress

This will bring you a text area where you need to enter this query:

UPDATE 'wp_comments' SET 'comment_author_IP' = '';

Click on the Go button below the textarea to run your query. That’s all, it will remove all IP addresses stored with comments in WordPress database.

Note: if you have a custom WordPress database prefix, then please adjust the wp_comments to your custom table prefix.

We hope this article helped you learn how to stop storing IP address in WordPress comments. You may also want to see our guide on how to add ask me anything anonymously in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

9 CommentsLeave a Reply

    • You may want to reach out to your theme’s support to ensure this isn’t something specific to your theme.

      Admin

  1. Thanks for this article.
    The question that i have is if i stop storing IPs in WP comments, will this break the functionality of plugins like Akismet ? or will they still work properly?

    • They will still work, however they may not be able to catch spam comments using known IP addresses used for mass spamming. So a lot of spam comments may appear in your moderation queue.

      Admin

  2. If comment IPs are stored in database, will stopping storing IPs improve or make database perform better?

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.