I need to password protect several pages and various areas of my templates if the page had a password enabled. This I can do on all subpages but on the homepage it's just not working.

I do not want to whole site password protected, which many plugines seem to do - the built-in WP password protection is fine for this purpose apart from the homepage issue. When the visitor lands on the site, they can see elements of the page but some content is hidden. The content needs to be unlocked by just a password and not a registered WP account username/password.

I assume the page used as home is treated differently than "normal" pages.

The only thing I can think of is to instantly redirect the homepage to a "normal" pge that looks identical - then the password protection function would work?

Google just offers either protecting the whole site (ie all you see in a login page) or protecting a normal page or using registered accounts to unlock content.

1 Answer 1


You can make the homepage password protected by creating a page and selecting it in the admin Settings > Reading > Homepage Displays. Then on the page settings make it password protected.

Then create a template called front-page.php and use conditionals to show/hide the content.

For Example...

if ( ! post_password_required( $post ) ) {
    // Password Protected Content
    // Password Form
    echo get_the_password_form();

More info on password protected pages.

Note: If you have already entered your password, you can delete your cookies and refresh the page to see the password form again.

  • Thanks, that's how we have set it up but it doesn't work for a page that is set to be the homepage. It displays the_content() regardless of whether you have setup a password for the page. Plus the if statement is also ignored.
    – CuCo
    Nov 21, 2018 at 16:25
  • Really? I am pretty sure I have used this setup before on a HP. I will have to look into more. Nov 21, 2018 at 16:31
  • I just setup a quick test and this approach is working for me. Try deleting your cookies and then hard refreshing the page. Once you enter the password once it saves it in a cookie. Nov 21, 2018 at 16:48
  • Could you make it a separate answer rather than a comment and I'll accept that as the answer.
    – CuCo
    Nov 21, 2018 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.