WordPress.org

Ready to get started?Download WordPress

Forums

Redirect 404 to login form, need help... (14 posts)

  1. Spencer Hill
    Member
    Posted 3 years ago #

    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!

  2. 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: http://codex.wordpress.org/Creating_an_Error_404_Page

  3. Spencer Hill
    Member
    Posted 3 years ago #

    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?

  4. 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.

  5. Spencer Hill
    Member
    Posted 3 years ago #

    Yep, you can navigate to http://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!

  6. 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:

    http://codex.wordpress.org/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.

  7. Spencer Hill
    Member
    Posted 3 years ago #

    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.

  8. 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: http://codex.wordpress.org/Function_Reference/wp_login_form

  9. Spencer Hill
    Member
    Posted 3 years ago #

    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!

  10. I like the idea of the conditionals - try it and let me know how it goes!

  11. 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...

    http://codex.wordpress.org/Function_Reference/is_user_logged_in

  12. Riavon
    Member
    Posted 2 years ago #

    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!

  13. jrothra
    Member
    Posted 2 years ago #

    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.

  14. hosselo
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.