# Shorter Login Sessions for Administrators

> Makes administrator logins expire sooner than everyone else's, limiting the damage of a forgotten logged-in browser.

- Type: PHP
- Runs: Run everywhere
- Category: [Login](https://wpide.com/library/category/login/)
- Tags: login, sessions, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/shorter-admin-sessions/

## Code

```php
// Session length for administrators, with and without "Remember Me".
$wpide_admin_session        = 8 * HOUR_IN_SECONDS;
$wpide_admin_session_remember = 2 * DAY_IN_SECONDS;

add_filter( 'auth_cookie_expiration', function ( $length, $user_id, $remember ) use ( $wpide_admin_session, $wpide_admin_session_remember ) {
    if ( user_can( $user_id, 'manage_options' ) ) {
        return $remember ? $wpide_admin_session_remember : $wpide_admin_session;
    }

    return $length;
}, 20, 3 );
```

## Notes

Applies from the next login; current sessions keep their expiry.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Shorter Login Sessions for Administrators" 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/
