-1

Have a brand new WordPress page where if one selects "Password protected" page in the page editor, it displays Protected: <page title> in the header of the page/page navigation, but does not prompt for the set password.

It does display the contents that are supposed to be loaded only after password verification. I have tried to illicit this password prompt after clearing cookies, and just in case using a browser I hardly ever use (IE, and especially not for working with/browsing my site)

What I have already tried to solve this, found on wordpress forum/help pages, in order, without luck:

  • Switched back to a default wordpress theme
  • Deactivated all plugins

Some folks mention augmenting the theme's functions.php file with functions that provide this functionality for theme's that strangely don't implement this functionality, but don't provide enough info on how.

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Tom J Nowell
    Nov 1, 2021 at 21:39

2 Answers 2

0

Your posts password form does not show because you typed the password in and unlocked the post, and it remembers you from when you submitted the password via cookies.

It doesn't have to be this particular post either, entering a password unlocks all posts that use that password present and future.

14
  • Not sure how that can be positively determined from someone not aware of the page in question, hence this question should be such in a comment. Have tried this on multiple browsers, including one I never use for editing this site until now.
    – user66001
    Nov 1, 2021 at 19:55
  • you don't have to do it for that specific post, entering a password will unlock all posts with that password
    – Tom J Nowell
    Nov 1, 2021 at 21:20
  • Sigh. I am also aware of how cookies work. I have one page that I have ever set as password protected on the site, and looked at all the other pages and none of them have password protection.
    – user66001
    Nov 1, 2021 at 21:30
  • so we do not know if password protection is broken, or if this is a unique issue to that specific post. You've already said that this happens on a vanilla WP install, with the default theme, and no plugins installed, so I don't see how this is possible unless WordPress itself was modified, there was user error, or there is code running that has not been shared, e.g. MU plugins, plugins considered mission critical, hosting software, etc.
    – Tom J Nowell
    Nov 1, 2021 at 21:34
0

You need to include this code in your template or you will not see any password field and the page will simply load normally.

<?php
if (post_password_required()) { 
    echo get_the_password_form();
} else { 
    // your protected template code here
}
?>

To make it easier, you can close the php to insert your straight HTML and such:

<?php
if (post_password_required()) { 
    echo get_the_password_form();
} else { ?>
    <!-- your HTML code here -->
<?php
}
?>
8
  • Thank-you! This is along the lines of what I mentioned in my original question I had seen before. Last question - Where does this code go? Hoping the answer isn't each page one wants to put a password on. I was hoping there is a template file, as eluded to in your answer, that this can be inserted into in order to apply to any page that theme presents which one at any point in the future wants to password protect?
    – user66001
    Nov 1, 2021 at 22:50
  • this check is already built into get_the_content in WordPress core: github.com/WordPress/WordPress/blob/… modifying the theme to do this is unnecessary, it won't change the behaviour, themes support this without any changes and the OP has already stated this happens in the default WP themes which definitely support passworded posts. The solution to this question won't be an addition to the theme, something needed to be added to WP or modified to cause this kind of behaviour, this is not normal
    – Tom J Nowell
    Nov 2, 2021 at 0:03
  • 1
    @user66001 it goes in your template for whichever page/post you want it on. If you're using the same template, then you'll only need to add it once. @tom-j-nowell Not all themes are using get_the_content or the_content to show all of the data, or it might be in a spot that reveals other content you'd rather not have shown. Example: the last project I was working on. Client only wanted the page title to show and all else to be hidden, and all data was from custom fields. He didn't say what theme he was using, only that he tried the default, so thought the theme might be the problem.
    – liquidRock
    Nov 2, 2021 at 0:20
  • @liquidRock the default themes use it, otherwise the theme would need to ignore post content or fetch it directly from the database. The OP reports that they're experiencing this on all themes including the twentytwenty theme with all plugins deactivated, so no pagebuilders. Check the chat link in the comment on the question, I asked a lot of questions about the OP's setup
    – Tom J Nowell
    Nov 2, 2021 at 0:32
  • Will do. Could be a plug-in conflict or something else out of whack.
    – liquidRock
    Nov 2, 2021 at 0:48

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.