Search code examples
phpwordpresscookiessession-cookies

Log out of Wordpress password protected pages when browser closes


I want cookies for password protected pages in Wordpress to expire when the browser window closes. I've tried the following in my functions.php file with no luck:

function custom_password_cookie_expiry( $expires ) {
    return 0;  // Make it a session cookie
}
add_filter( 'post_password_expires', 'custom_password_cookie_expiry' );

Any help would be greatly appreciated


Solution

  • This problem had been solved here. Please see the link:

    function wpse_191369_post_password_expires() {
        return time() + 10; // Expire in 10 seconds
    }
    
    add_filter( 'post_password_expires', 'wpse_191369_post_password_expires' );
    

    For more details:

    https://wordpress.stackexchange.com/questions/191369/how-to-make-page-post-password-protected-so-you-must-reenter-everytime-you-visit