Password Protect Custom Page

When you select password protected option in page back-end, It by-default works for content only. i.e. the_content()

But if you want to password protect whole page or have a custom template, you need to have the following structure.

<?php
global $post;
get_header();

if ( ! post_password_required( $post ) ) {
      // Your custom code should here
}else{
    // we will show password form here
    echo get_the_password_form();
}

?>

Try using this structure

Leave a Comment