How to Remove and Stop Storing an IP Address in WordPress Comments

Whenever a user or visitor comments on your WordPress site or blog, along with their name, email address, and web address, their IP address is also recorded automatically and shown to you in the Comments dashboard. This is helpful if you want to quickly ban or block an IP address for whatever reason. Even though you can easily customize different fields in the comments dialog box, WordPress doesn’t provide any options to remove the IP address or prevent itself from recording it. This is especially important if you have a privacy policy of not collecting any user data unless they submit it themselves.

No matter what the reason is, you can easily stop WordPress from recording IP addresses in user comments or even remove any existing IP address logs in WordPress comments. The following lays out all the steps for you.

Note: before doing anything, make sure that you have a good backup of your WordPress site (both files and database). This allows you to revert back if anything goes wrong.

Stop Recording IP Addresses in Comments

Thankfully, stopping WordPress from recording IP addresses in comments is straightforward. To start open your FTP client, navigate to your current theme folder and open the file “functions.php.”

wp-remove-comment-ip-address-open-functions-file

Once the file has been opened, scroll down to the bottom of the file, add the below code and save it.

//Stop recording IP address in comments
function mte_remove_commentsip( $comment_author_ip ) {
return '';
}
add_filter( 'pre_comment_user_ip', 'mte_remove_commentsip' );

wp-remove-comment-ip-address-add-code-snippet

What the above code snippet does is remove the IP address from the comment before adding it to the database. With this code WordPress will not record a user’s IP address when they comment on your site. If you want to revert back, simply remove the added code snippet.

Alternatively, if you don’t want to mess with your WordPress files to add custom code snippets, you can use a free plugin called Remove IP to achieve the same result. Just open your plugins Dashboard, search for the plugin and install it. Once installed, click on “Activate Plugin.”

wp-remove-comment-ip-address-activate-plugin

The good thing about the plugin is that it doesn’t have any additional settings. As soon as you install it WordPress stops recording the IP addresses in comments. To revert back, deactivate and delete the plugin from your plugins dashboard.

Remove Existing IP Addresses from Comments

Even though you’ve stopped WordPress from recording visitor IP addresses in comments, you didn’t remove the IP addresses that are already recorded. If you also want to delete all the previously recorded IP addresses in comments, all you need to do is execute a single line of SQL query.

Note: the following instruction assumes that you are using cPanel and phpMyAdmin to connect to your database. The MySQL command will work for any database client, though.

To do that, open your cPanel, and search for and open “phpMyAdmin.” Once the phpMyAdmin page has been opened, select your database from the left pane.

wp-remove-comment-ip-address-select-database

After opening your database, navigate to the “SQL” tab. This is where you will run your custom SQL queiries.

wp-remove-comment-ip-address-select-sql

Here in the page enter the following query in the text box, and click on the “Go” button appearing on the bottom-right corner.

UPDATE wp_comments SET comment_author_IP = '';

wp-remove-comment-ip-address-execute-query

As soon as you execute the query, you will receive a confirmation regarding how many rows are affected.

wp-remove-comment-ip-address-query-executed

You’ve successfully removed all the previously recorded IP addresses in the WordPress comments.

wp-remove-comment-ip-address-ip-addresses-removed

Do comment below sharing your thoughts and experiences about using the above methods to stop WordPress from recording IP addresses and to remove existing IP address details in comments.

Image Credit: NeilPatel

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Vamsi Krishna Avatar

Read next

Suzanne Simard sealed paper birch and Douglas fir seedlings inside plastic bags, fed them carbon-14 and carbon-13 dioxide, and nine days later found carbon had crossed between species through fungal threads in the British Columbia soil beneath her boots
A species of jellyfish called Turritopsis dohrnii can revert its adult cells back to a juvenile polyp stage when injured or starving, effectively restarting its life cycle, and biologists have so far failed to identify any natural limit to how many times it can do this.
A Japanese man named Jiroemon Kimura, who lived to 116, was born in 1897 when Queen Victoria still ruled and died in 2013, meaning a single human life personally overlapped with the invention of the airplane, the atomic bomb, the internet, and Instagram
The Hollywood sign originally read HOLLYWOODLAND when it was built in 1923 as a real estate advertisement for a housing development, and it was only meant to stand for 18 months, but nobody ever got around to taking it down and the city eventually adopted it as a landmark
Almost all of the world’s internet traffic does not travel by satellite but through fibre-optic cables lying on the ocean floor, a hidden web of wires crossing the deepest parts of the sea to connect the continents.
People who flip their phone face down on every table aren’t being secretive. They figured out that staying interruptible meant handing their time to whoever rang first
Twitch vs. Facebook Gaming vs. YouTube Gaming: What’s the Best Live Game Streaming Platform?
Chrome Extensions Ownership Transfer is a Direct Threat to You: How to Stay Safe