678-807-9676 hi@yazminmedia.com

Force Login on Password Protected Page

If you’ve ever needed to create a password protected are on your website, WordPress has you covered. The only problem with their solution is that once you login to the password protected area, WordPress creates a cookie to save your login hash, allowing you to visit the page any time you want… no password required.

This is by design and is great if it is what you want, but if you need your users to enter a password for each visit, you need a solution to force login on the password protected page.

Force Login on Password Protected Page

Fortunately, it’s a quick solution involving a short snippet… and all it takes is two simple steps:

Step 1: Create a site specific plugin or child theme.

Step 2: In your site specific plugin file or the functions.php of your child theme, add the following code:

Basically, this sets your cookie’s time period to 0, meaning the cookie will reset itself once the session expires. This is what forces your visitors to have to re-enter a password each time they visit.

Pretty simple, right?