Home › Forums › General Issues › 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?
Wrap your acf output calls with a conditional statement using
post_password_required(), example here:
Ok, thanks! I will give it a shot.
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…)
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 🙂
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.