Logout Button for password protected pages

Hi guys,
I´ve got some difficulties with password protected pages. Once you´re logged in, the password is saved, even after closing the browser. If tried several things e.g. expire time of password cookie etc. but nothing worked. Also a custom button which was mentioned here didn´t have any effect.
Could you provide any solutions or work around?

Thank you very much!

Hello @gehess,

Thanks for writing in!

The code in this thread (https://theme.co/apex/forums/topic/password-protected-page-logout/) does not apply to the issue. The code is for the Protected Content shortcode which is built in X.

By default, there is no logged out button for any password protected page or post. This is a default of WordPress. WordPress stores this password in a browser cookie so readers don’t have to re-enter passwords if they visit the same page multiple times. You can find out mode information about it from here:

To really have a logged out button, you will be needing to install a 3rd party plugin:

Hope this helps.

Thanks for your answer! I tried some plugins, but they didn´t change anything. I found this in wp-login.php due to your link:

  *Filters the life span of the post password cookie.
	                 * By default, the cookie expires 10 days from creation. To turn this
	                 * into a session cookie, return 0.
*
                 * @since 3.7.0
	                 *
                 * @param int $expires The expiry time, as passed to setcookie().
	                 */
                
$expire  = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );

Then I went to search for some modication and found this:

add_filter( 'password_reset_expiration', function( $expiration ) {
    return 1; // A second
});

and that:

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

Could you tell me, which snippet should work, because at the moment, nothing changes if I close the browser and reopen it. I´m staying logged in …
Some help would be appreciated!

Hello @gehess,

I could not guarantee if the snippet would work. I could suggest that the 3rd party plugin should work instead.
I tested out “Protected Posts Logout Button” plugin and it displays a logout button perfectly.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.