Support

Account

Home Forums General Issues Hide ACF if password protected

Solved

Hide ACF if password protected

  • I have a page on a site that just needs simple password protection – easy enough in WordPress, right? Except that most of the content on that page is generated through ACF – and I guess since it is not “content” it still shows on the page before they enter a password.

    I have tried a bunch of different plugins and tools to try to protect the whole page, including the Advanced Custom Fields, but no dice. The ACFs still always show no matter what I do.

    Is there a way to hide those fields until the password is entered on a password-protected page?

  • Ok, thanks! I will give it a shot.

  • Hi Websydaisy,

    I’m running into the same issue.
    Can you explain how you fixed this one, maybe with a code-example?
    (The provided code-examples from Thomask are great, but I just don’t understand what to do and/or how to implement these…)

  • Solution:

    Note that there’s an IF and an ENDIF which need to be wrapped around the ACF fields.

    Also note that the default WP the_content() code must remain in place — even if you’re not using it for content in your template.

    
    <div class="entry-content clearfix">
    
    <!-- HIDES ACF FIELDS for use with WP password protect feature -->
    <?php if( !post_password_required( $post )): ?>
    
    	<h2><?php the_field( 'business_name' ); ?></h2>
    
    	<p><?php the_field( 'client_name' ); ?></p>
    
    	<p><small><?php the_field( 'date' ); ?></small></p>
    
    	<h1><?php the_field( 'introduction_title' ); ?></h1>
    
    	<p><?php the_field( 'introduction_text' ); ?></p>
    
    <!-- ENDS HIDE ACF FIELDS with WP Password Protect -->
    <?php endif; ?>
    
    <?php the_content(); ?>
    
    </div><!-- .entry-content -->
    
    
  • Just want to say thanks to those who responded here! Fixed my problem in no time 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Hide ACF if password protected’ is closed to new replies.