• I’d like to display a sign in form instead of the error page when users try and access a private page but I’m struggling to find any documentation on how to accomplish this. Can someone point me in the right direction? Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • To customize the 404 page, just edit your theme’s 404.php template or create one from scratch. You can add anything you like there.

    Ref: https://codex.www.ads-software.com/Creating_an_Error_404_Page

    Thread Starter Spencer Hill

    (@ws5f3dj7)

    Thanks for the reference zoonini but that doesn’t seem to provide the correct information regarding private pages. I thought maybe it was technically a 403 – forbidden but WordPress doesn’t seem to classify it as that so I’m still stuck without a solution.

    Any other suggestions?

    Can you link to an example of the type of page you’re looking to customize? I’m not clear what you’re trying to do.

    Thread Starter Spencer Hill

    (@ws5f3dj7)

    Yep, you can navigate to https://www.insurancestoreonlineforbrokers.com/private/ and you’ll notice it says “Page not found”. When in actuality, it know’s the page is there, it’s just marked as private. And because of this, it should say “Private page, please sign in.”

    Thanks for your help!

    Hi Spencer,

    Sounds like you actually want the status of that page to be “password-protected” instead of “private”. Have a read about the way content visibility works in WordPress and see what you think:

    https://codex.www.ads-software.com/Content_Visibility

    The definition of a private page in WordPress is that it’s hidden, as you’ve seen. I would try changing the status of that page to password-protected and see if it gives you the login form you’re looking for.

    Thread Starter Spencer Hill

    (@ws5f3dj7)

    Thanks for the reply again, and for the perspective.

    I’m actually already familiar with password protected, and that doesn’t seem to be the right solution. I need users to be prompted to sign in with their username and password.

    Ah, I think I’m starting to understand what you’re trying to do. (At least I hope I do!)

    Could you create a 404.php template file and make it a combined error and login page.

    In other words, it would say something like:

    This page cannot be found. To access a private page, log in here:

    … and insert the code to display a login form – <?php wp_login_form( $args ); ?>

    Function reference: https://codex.www.ads-software.com/Function_Reference/wp_login_form

    Thread Starter Spencer Hill

    (@ws5f3dj7)

    I thought about that, and I think it would suffice as a workaround if I couldn’t truly separate the two. But this seems like such a core/common feature I’m surprised there’s not already a elegant solution.

    What if we ran with that idea, but we inserted some sort of conditional statement that says “If the user is signed in, say this… else …” And another conditional that says “if the page status is private… else if the page is not found…

    You know?

    THANK YOU!

    I like the idea of the conditionals – try it and let me know how it goes!

    By the way, there is definitely a conditional for a user’s logged-in status (see below) but I’m not sure if there’s one to test for a private page. The problem is that what it looks like – and maybe someone more versed in this than me can confirm – is that when a page is private, it just seems to redirect you to the generic 404 error page. And if the user is already logged in, then they should automatically see the correct content, so on second thought I’m not sure you actually need that condition. However, it’s been a long day and maybe there’s another workaround I’m not thinking of…

    https://codex.www.ads-software.com/Function_Reference/is_user_logged_in

    I am trying to do the exact same thing as Spencer Hill! I too am shocked that this isn’t something that is easily done. If someone bookmarks the private page then they get the horrid ERROR 404 instead of a gentle reminder to ‘please log in to view this page’ with the handy log in form right there in front of them. There is a plugin called “Private Only” that tries to do this, but its buggy and doesn’t seem to work well with the latest version of WP (3.3). I can’t find any code or any other plugin to resolve what seems to be a simple redirect for a private page to go to the login page (if visitor isn’t logged in). ?? Boo!

    Spencer’s on to an idea that I think many would appreciate. I’ve searched for a plugin to do the trick, but none that I can find that work right. His idea of having URL’s to private pages display a login prompt rather than a 404 error is great. Customizing the 404 is one option, but not ideal.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Redirect 404 to login form, need help…’ is closed to new replies.