Privacy PHP Beginner

Stop Storing IP Addresses With Login Sessions

Stop WordPress saving each logged-in user's IP address and browser details in their session records.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 4 lines
add_filter( 'attach_session_information', function ( array $session ): array {
	unset( $session['ip'], $session['ua'] );
	return $session;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Every time someone logs in, WordPress stores their IP address and browser user agent with the session in the database. Most sites never use that data. Not storing it is a small, easy win for data minimisation.

How it works

When a session is created, WordPress builds its record through attach_session_information, including ip, ua (user agent) and the login time. The snippet removes the first two before the record is saved.

Things to watch

  • Existing sessions keep their stored data until they expire or the user logs out.
  • Some security plugins show IP addresses for active sessions, and those columns will be empty.

How to test it

Log out and back in, then check your user’s session_tokens entry in the usermeta table. It should have expiration and login but no ip or ua.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only