Example 1 — Show a form for locked posts
Print the password form and stop if the post is locked.
<?php
if ( post_password_required() ) {
echo get_the_password_form();
return;
}
the_content(); How It Works
- If the post is locked, the check is
true. get_the_password_form()returns the form HTML, and we print it.returnstops the template so the content is not shown.

