Stop storing IP addresses in comments

By default, WordPress will capture IP address from anyone who leaves a comment on your site. That means that the IP address will be stored into a database and it will be showed to an administrator while moderating comments.

Before you stop here and decide to remove IP addresses from comments, take a second to reconsider. If you stop WordPress from storing IP addresses in comments, you will get a bit cleaner database. But how many comments do you actually get? Will this really make a difference for you?

If you leave this extra information, you can sort comments by IP, you may be able to control specific spammers by blocking their IP addresses or even report them on certain activities. There are definitely pros and cons of storing IP addresses in comments, but if you have decided to remove them, here’s what you can do.

Remove IP addresses from future comments:

  1. Open functions.php file
  2. Copy and paste the following:
  3. function wploop_remove_ip_comments( $comment_author_ip ) {
    return '';
    }
    add_filter( 'pre_comment_user_ip', 'wploop_remove_ip_comments' );
  4. Save changes

If you navigate to Comments and open the list of the most recent comments, you will notice that IP addresses are still there. That’s because this function will take care of the future comments only. If you want to remove the old ones, you will need an extra step.

Before you continue, make sure that you have a backup of your WordPress.

Remove IP addresses from old comments:

  1. Open phpMyAdmin
  2. Run a new query:
  3. UPDATE 'wp_comments' SET 'comment_author_IP' = '';

    This update will delete all IP addresses from your comments. Since the function mentioned above will do the same for any future comments, you can now forget about IPs in comments.

    Interested in customizing comments even more? Check out our other articles about comments.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *