Password Protect Custom Templates in WordPress

0 Flares 0 Flares ×

It seems that the built in password-protect function of WordPress only protects the <?php the_content(); ?> portion of the post. But what about custom content within a custom template such as advanced custom fields? I ran into this issue and it took me a while to find a proper solution. There are many solutions out there that people say work but the didn’t work for me. The only what that did was the following:

<?php if ( post_password_required() ) { 

  echo get_the_password_form(); 

} else { ?>

  'Password Protected Custom Content'

<?php } ?>

This shows only the form on password protected pages, and once the form is entered it shows the custom content. Make sure you are not logged in when testing the page because I believe that it will automatically skip the password protection for logged in users. Also clear your cache after each test if you are using a caching plugin. Clear both the plugin cache and your browser cache. Test on another computer as well to be sure. Don’t make the same mistake I did! I always used to think that if it worked on my computer it should work on other peoples computers. That is just lazy thinking.

Anyway if you have any questions/concerns leave a comment.

This solution was found in the comments of this post.

About Frank Apicella

Frank Apicella is the founder of Snippet Central and HtotheML. He helps people make websites. However and whichever way he can accomplish it. With a strong background in Wordpress he can most certainly help you out.

Leave a Reply