How to password protect a WordPress custom page template

You may have password-protected a page from within the WordPress admin, only to find that the content is still visible when you visit the page. Here’s how to fix that.

You may have password-protected a page from within the WordPress admin, only to find that the content is still visible when you visit the page.

If you’re using a custom page template for that page, you’ll need to include the following code within the loop to tell WordPress to honour the page’s password protection:

<?php
if ( post_password_required() ) {

echo get_the_password_form();

} else { ?>

// your page content here

<?php } ?>

Hope that helps, and let us know in the comments below if you have any questions!

 

We’ve finished a site for music blog Just Tracks!

How to Delete the node_modules Folder on Windows