# Don't Keep Full IP Addresses in Login Sessions

> Shortens the IP address and drops the browser details WordPress stores with every login session, so session records no longer hold full personal data.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: sessions, ip-address, users
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-mask-session-ip/

## Code

```php
add_filter( 'attach_session_information', function ( $session ) {
    if ( ! empty( $session['ip'] ) ) {
        $session['ip'] = wp_privacy_anonymize_ip( $session['ip'] );
    }

    unset( $session['ua'] );

    return $session;
}, 20 );
```

## Notes

Security snippets that compare session IPs will compare the shortened address instead.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Don't Keep Full IP Addresses in Login Sessions" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
