How To: Setup Password Protected Posts in WordPress

Setting up your theme to support password protected posts in WP is easy. This tutorial assumes you are setting it up on standard posts, but if not, you will just make adjustments to the templates being edited and the filters to reflect your targeted template.

  1. In your single.php template, wrap the content in a conditional statement that will render the password form if one is called for:
    <?php if(post_password_required()) { 
    echo get_the_password_form(); 
    } else {
    POST CONTENT HERE
    } ?>
  2. You will also need to filter password protected posts from post list pages on the front end. Add this to your theme functions to do that:
    <?php function wpb_password_post_filter( $where = '' ) {
    if (!is_single() && !is_admin()) {
    $where .= " AND post_password = ''";
    }
    return $where;
    }
    add_filter( 'posts_where', 'wpb_password_post_filter' ); ?>

That should be all you need to do. Go forth and prosper in your exclusive little password protected world.