How to Prevent my WordPress Website from Logging Me Out

,

If you’ve spent time blogging on a WordPress website you’ve come across the dreaded blank WordPress page with the following text: -1

This error occurs, for example, when you’ve begun a post but fail to complete it for an extended length of time. This is a simple issue regarding cookie expiration.

In my case, I started a post one evening and decided to return to it in the morning. Upon my return I completed the post and pressed the Publish button only to be presented with a blank page showing -1.

Luckily I was able to hit the Back button in my browser which successfully restored my work to my tab. I copied the text, just to be sure, and tried to publish the post again. This time it succeeded without issue. What a relief.

To prevent your WordPress website session cookie from expiring on you we’ve discovered a code snippet which will keep users logged in indefinitely. NOTE: Implementing this code snippet is not recommended! It is only intended for a blogger with additional security measures in place and who only uses personal computers.

 

Would you like prompt assistance? If you don’t have time or are not comfortable taking the risk of adding custom code to your website, let us get this done for you now!

 

Preventing Logout

To utilize this snippet to prevent WordPress from logging you out of your session in the middle of your work add the following code to your functions.php file. Your functions.php file is located within your currently active theme or child-theme. We always highly recommend implementing a child-theme for your WordPress website. Do you need a child theme set up? We can help.

 

/*
** Keep Users Logged in Forever
*/
add_filter( 'auth_cookie_expiration', 'keep_users_login' );
function keep_users_login( $expirein )

{
    return "31557600"; // 1 year (in seconds)
}

 

Alternatively, you may set it so that only yourself (the administrator) is logged in ‘forever’ using the current_user_can function.

 

/*
** Admin-Only Function
*/
if( current_user_can( 'administrator' ) )
{
    // Function goes here
}

 

An example of the combined code follows:

 

/*
** Admin-Only Function
*/
if( current_user_can( 'administrator' ) )
{
    // Function: Keep Admin Logged in Forever
    add_filter( 'auth_cookie_expiration', 'keep_admin_login' );
    function keep_admin_login( $expirein )

    {
        return "31557600"; // 1 year (in seconds)
    }

}

 

We hope this article has helped prevent the “-1 blank page” issue from ever occurring again on your WordPress website. Should you need assistance implementing this solution on your existing WordPress website simply reach out to us at (239) 961-8285

 

We hope this article has helped you. If you found it helpful please take a moment to like us on Facebook, share this on your social media or buy us a cup of coffee.

 

Hire us to get it done for you!

Select, WordPress Support Basic, from the drop down list on the form below. We’ll help implement the above solution into your WordPress website today.