Here is the function to redirect non-users to login page.
function redirect_user() {
if ( ! is_user_logged_in() && ! is_page( 'login' ) ) {
$return_url = esc_url( home_url( '/login/' ) );
wp_redirect( $return_url );
exit;
}
}
add_action( 'template_redirect', 'redirect_user' );
Related Posts:
- Using `auth_redirect` : keeps asking me to login even when I’m logged in
- How can I force the user to log in, even if they’re already authenticated?
- Redirect user to original url after login?
- Login redirect to previous page
- Redirect to referring page after logging in
- check first time login only
- How to change the default logout link on WordPress Admin
- How to redirect after login, the working way?
- Password change when the user login first time
- Custom login form redirect to external site
- handling login/logout redirects
- Authentication / login mechanism (non wp-admin)
- Restrict Access to wp-login.php
- Redirect users after first login
- Redirect to current page after wordpress login
- wp-login.php — redirect logged in users to custom URL
- Redirect user after login/registration globally
- Redirect to login page
- Redirect user after logout
- how to do logout redirect to current url
- How to redirect user to specific page based on the input password
- How do I redirect a user when he is logged in after clicking on a menu
- How to modify the Register link in the login page?
- Changing “Lost Password Email Link” to custom password reset page
- homepage redirects to login page when user session expires
- How to redirect user to a specific page based on username?
- Redirect after password update
- How to redirect user after login to a specific page?
- Redirect Logged In User if page is wp-login.php and $_Get[‘level’] = X
- Redirect when accessing /login when logged in
- How to redirect after login getting a variable from url (for example with the language)
- If User is NOT Logged in and Page ID is not 6 – Redirect to Login
- Redirect to Current Page after Login
- How to include error message on login
- Login redirect problem
- How to redirect on login to a specific page if a specific meta user is empty
- redirect Login problems
- Redirect user to previous page after signup from custom form
- User is logged in after Stripe payment, then redirected, but is then logged out again
- After logout browser’s back button into twenty sixteen theme profile
- Login Redirect – Multiple Scenarios
- WooCommerce – Redirect to a product after login
- Usage of the login_redirect filter
- Login/Register redirect user with message
- Redirect user to original url after login?
- Custom form redirect after login
- Custom redirect user after login based on metadata
- Redirection on Custom page
- Redirect user to specific link after login
- Load function with login_redirect
- Prevent “/login” to redirect to “/wp-login”
- Redirect User to login page
- All URLs Redirect to Main Page
- How to redirect user after login to the page called by his first name?
- redirect doesn’t work while using example code
- Why I am not able to direct user to my blog section without login?
- Redirect After Login Error
- Redirect certain pages if user logged in
- Force User Login
- Login redirect shows white page in firefox
- wp_login_form redirect
- Login redirect to previous page
- Trying to re-direct users to specific page based on an ACF variable
- Disable redirect to homepage after successful Login, Stay on Current Page
- Redirect to custom login page if not logged in and redirect to home if logged in user try to login, how?
- wp_login_form() redirect same page
- How force WordPress redirect to current custom page after login
- Hide a Post everywhere except on redirect
- Conditional Login Redirect
- Keep the old referrer after failed login
- Redirect user after login to prior page through a wp_login hook
- How can force redirected to login for two or more pages to view or access
- Changing auth_redirect() page
- How to redirect user to Referrer Page using wp_signon in Custom Login Page in WordPress
- Redirect after login when WordPress in subdirectory
- HOW do you Redirect buddypress login to EDIT tab not PROFILE tab on profile page? [closed]
- Login redirects to home page and doesn’t log in
- WordPress not loggin user and redirecting after custom registration
- redirect_to ignoring the SSL
- Redirect user on login using extra field value on login form
- Woocommerce login to specific page or referrer
- wp-login.php redirect problem
- login redirect problem – db charset issue?
- How to modify the WordPress comes with redirect
- Conditional redirect on login using referring URL
- Redirect problem: How to redirect to the original URL after login
- Custom Login Plugin Redirects to wp-login.php After Site Migration
- Login Form Redirection
- Redirect user to login and then to page where they came from
- WordPress Login Page redirecting after failed login
- Logging back into WordPress after logging out and having issues with ‘loggedout=true’ in redirect URL
- login page not working [closed]
- Redirect after user changes password
- redirect users to the login page
- WordPress redirect to splash page once a day for the first week
- Accept (once only) policy page on login
- login_redirect for Mobile Web
- wp_login_form: Redirect to dynamic url according to username
- How to disable login and registration pages?
- Redirecting logged in users to custom URL