Password Protected Content

How to use the password protection feature in WP when you’re not using the_content()

<?php
/* Template Name: Landing */

/**
 * Landing Content
 *
 */
function ea_landing_content() {
    // Password Protection
    if( post_password_required() ) {
        global $post;
        echo '<div class="landing-section"><div class="wrap">';
        echo '<h2>Password Required</h2>';
        echo get_the_password_form( $post );
        echo '</div></div>';
        return;
    }
  
    // Landing page content
    $sections = ea_cf( 'ea_landing_content', get_the_ID(), array( 'cf_type' => 'complex' ) );
    //...
}
get_header();
ea_landing_content();
get_footer();
Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk