Change How Long Polylang Remembers the Language
Sets how long Polylang's language cookie lasts (one year by default), for example a single session on kiosks and shared computers, or 30 days for privacy-conscious sites.
Opens WPIDE on
Code
$wpide_seconds = 30 * DAY_IN_SECONDS; // Cookie lifetime in seconds; 0 = session only.
add_filter( 'pll_cookie_expiration', function () use ( $wpide_seconds ) {
return max( 0, (int) $wpide_seconds );
} );
Notes
0 makes it a session cookie that disappears when the browser closes.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.