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:
http://codex.wordpress.org/Using_Password_Protection#Protect_Custom_Fields
http://codex.wordpress.org/Function_Reference/post_password_required
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 🙂
The topic ‘Hide ACF if password protected’ is closed to new replies.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.