Is there a way to have a page displayed to the public, but have an extra custom field that doesn't display unless a password is entered?

I suppose I could do entirely manually without WordPress functions at all but I'd like to know if there was a WordPress solution.

1 Answer 1


I would do it the other way around: Put the always visible text into a custom field per metabox, and protect the post content with a password.

In your theme, always show the custom field, and let WordPress handle the password protection.

Sample code for the theme:

while ( have_posts() )

    if ( post_password_required( $post ) )
        print '<h1 class="post-protect-notice">' .
            __( 'Protected Post', 't5_theme' )
            . '</h1>';
        // custom field
        print wpautop(
            get_post_meta( get_the_ID(), '_always_visible_content', TRUE )
        // show regular content
  • Thanks Toscho, gonna look into that, but how to show the content with password on the same page? Or should I make 2 seperate pages, one password protected and one not
    – Lucky Luke
    May 24, 2013 at 11:47
  • @LuckyLuke See my update with a code sample.
    – fuxia
    May 24, 2013 at 11:55
  • Thats good, but what determines if post_password_required? None of my users are logged in, but I want to give out a password manually to my friends to see this private content (like a price).
    – Lucky Luke
    May 24, 2013 at 12:08
  • post_password_required() is TRUE if you set a post password. You could also let your friends create subscriber accounts and show the extra content only when is_user_logged_in() is TRUE.
    – fuxia
    May 24, 2013 at 12:11
  • Yeah thats what I thought about checking if they are logged in. But for your first option, let me see if I get you. I set a post password, but even on restricted pages I show all the info from the custom fields except the main content (which contains the price). If they enter password then all is shown. Correct?
    – Lucky Luke
    May 24, 2013 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.