I'm considering building a modal login page for my wordpress blog. I have a static link on my menu linking to custom /login page. Else, I have a redirect from private pages, where user needs to be logged in to proceed:

if ( !is_user_logged_in()) { wp_redirect( '/login/' ); }

Any ideas how I can build this modal to popup whenever a user is not logged? And if he refuses to log or register to be redirect to home page for example?

  • I can see multiple questions here, "How do I tell javascript if I'm logged in or out in WordPress?" "How do I display a login prompt?" "How do I redirect the browser in javascript?". This suggests your question is too broad. We also have a 1 question per question policy, perhaps you should edit down your question to a specific thing then ask multiple questions for each part? Else it's likely to be closed as too broad. Also if the user turns off javascript and removes the modal via the browser dev tools, and reads your article anyway
    – Tom J Nowell
    Aug 8, 2014 at 9:49
  • Well, I didn't know about turning off javascript would cause a problem. I guess in that case, that kind of information should go trought php, becouse I can't risk a non logged user to preview my pages. Anyway, I can build the login and register into modal, but redirecting stays still a mystery. Aug 8, 2014 at 10:07
  • Redirecting via javascript is offtopic, but you can do it by setting window.location = 'http://example.com';
    – Tom J Nowell
    Aug 8, 2014 at 10:21


Your Answer

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

Browse other questions tagged or ask your own question.