Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
WordPress tutorials
by experts

How to Stop Storing IP Address in WordPress Comments

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to stop storing IP addresses in your WordPress comments?

By default, WordPress logs and stores the IP addresses of commenters to protect you against spammers. That said, with the rise of data privacy laws, you may want to stop this functionality to protect your website visitor data.

In this article, we will show you how to stop storing IP addresses in WordPress comments.

How to Stop Storing IP Address in WordPress Comments

Should You Stop Storing IP Addresses in WordPress Comments?

Unless your commenters use a VPN, WordPress will store their IP addresses on your website.

This is mainly used to combat spam comments from suspicious IP addresses. Some security plugins may also use IP addresses to put users in a comment blacklist or block malicious IP addresses to prevent threats like brute force attacks and DDoS attacks.

That said, some users may feel uncomfortable knowing that their IP address is logged after they leave a comment. They may think that this information can be used against them, which can make them hesitant to engage with your WordPress website.

If your website caters to a global audience, then storing IP addresses without user consent can also make your site less compliant with the General Data Protection Regulation (GDPR). This is because the GDPR classifies IP addresses as personal data.

Most WordPress web hosting providers keep raw access logs of all visitors to your website for a limited period of time. Plus, you can view these IP addresses when viewing the Comments page in the WordPress dashboard.

Now, let’s look at how to stop storing IP addresses and improve your WordPress security. Here is an overview of what we will cover:

This first method uses the WPCode plugin. We will use this plugin to insert a custom code snippet that stops your website from storing IP addresses from the comments section.

If this is your first time using code, don’t worry. WPCode’s user-friendly interface makes it easy to insert and manage custom code, even for a beginner.

To use WPCode, you need to install the plugin first. For more guidance, check out our article on how to install a WordPress plugin.

Note: This article will use the WPCode free version, but feel free to upgrade to a Pro plan for more advanced features like conditional logic and scheduled snippets.

Now, you need to go to Code Snippets » + Add Snippet from your WordPress admin panel. After that, click the ‘Use snippet’ button under ‘Add Your Custom Code Snippet’.

Adding custom CSS in WPCode

You will now see the Create Custom Snippet screen.

First things first, you have to add a title for your code snippet. It can be something like ‘Disable IP Address in Comments.’

In the Code Type dropdown, choose ‘PHP Snippet.’ Then, in the Code Preview box, you can insert the following code:

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

After that, make sure the toggle in the top right corner says ‘Active’ and click ‘Save Snippet.’

It should look like this.

Removing IP addresses in the comments using WPCode

Now, the next time someone leaves a comment, you won’t see their IP address on the WordPress Comments page.

However, you will notice that previous comments still have this information stored. We will talk more about how to remove this data in the next part of the tutorial.

What the comment looks like after removing the IP address using WPCode

How to Remove IP Addresses From Older WordPress Comments

To remove IP addresses from your older WordPress comments, you will need to use phpMyAdmin. It’s a database management platform that usually comes with your WordPress hosting control panel.

Note: Before you do anything, we strongly recommend you back up your WordPress database first. That way, you can restore the database if you make a critical error.

Once you do that, you need to log in to your WordPress hosting account and look for the phpMyAdmin menu.

For Bluehost users, you will find phpMyAdmin by going to ‘Websites’ and selecting the website you want to configure in your dashboard. It should be under ‘Quick Links’.

Navigating to the phpMyAdmin in Bluehost

Inside phpMyAdmin, you can navigate to the ‘SQL’ tab.

After that, enter this query below:

UPDATE wp_comments SET comment_author_IP = '';

Note that if you have a custom WordPress database prefix, then please change wp_comments to your custom table prefix.

Once that’s done, simply click the ‘Go’ button below the text area to run your query.

Removing IP addresses in older WordPress comments using phpMyAdmin

At this stage, just go back to your WordPress Comments page to see if the query worked properly. That’s it!

We hope this article has helped you learn how to stop storing IP addresses in WordPress comments. You may also want to see our expert picks for the best WordPress security plugins and our guide to the tell-tale signs hackers have hijacked your WordPress site.

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.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

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

12 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Prajwal Shewatkar says

    As privacy laws are getting stricter day by day it is important to eliminate collection and long-term storage of personally identifiable information. I’ve been using a plugin to remove IP addresses previously. thanks a lot, WPbeginner for providing such a useful code snippet.

  3. Jiří Vaněk says

    Thank you for the article. Many people in the Czech Republic are very sensitive to any private data after the introduction of GDPR. This is definitely useful so that they don’t have to worry about their sensitive data being displayed somewhere. One then feels much more free to write a comment.

    • WPBeginner Support says

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


  4. Melika says

    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?

    • WPBeginner Support says

      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.


  5. Matija says

    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.