WordPress has a built-in feature that allows you to protect pages and posts with a password. You can set a unique password for each page or post.
Step 1: In your page or post, click on “Visibility: Edit” in the publish block.
Step 2: Select “Password protected” and enter your desired password.
Step 3: Publish the changes.
Done!
After these steps, you will see a password field on the page or post where you have set it.
Simple, right?
Hide more than just the content?
With this function, WordPress only protects the content that is loaded with wp_content(), but not the custom fields that you have programmed in a page template or extra content areas via the Secondary content plugin.
If you also want to hide these, you can add this code to the template to hide that info:
<?php if ( !post_password_required() ) { ?>
This will also be hidden now!
<?php } ?>