function after_login_redirect_to_destination(){
if (!is_user_logged_in() && !is_home()){
$redirect = home_url() . '/wp-login.php?redirect_to=' . urlencode( $_SERVER['REQUEST_URI'] );
wp_redirect( $redirect );
exit;
}
}
add_action( 'wp', 'after_login_redirect_to_destination', 3 );
the above sample code works and redirect to the login page and after successfull login it will redirect to home page. Whenever a non-logged in user try to access the home page, it will redirect to the login page and after successfull login then it will redirect back to destination page. Here the destination page(home page in this case) . You can modify the code above to your redirect to your custom login page and after success it will then redirect to the current page you were
Hope that helps!
Related Posts:
- Action wp_login_failed not working if only one field is filled out
- Change register form action url
- Restricting frontend acess based on user role otherwise redirect to login form
- wp_get_referer not working properly after wp_redirect
- Login redirects and query strings
- How To Change Wp Register/Login URL Permanently To My Custom Page
- Adding rewrite rule dynamically for search results redirecting to 404 URL
- How can I login as admin after redirect to custom login page
- Redirect wp-login
- Changed Wordress Address URL Accidently
- Do more action after login successfully
- How to redirect home page to another page after login for all user?
- Hide Author page from others
- Require re-login when logged-in user attempts to access restricted page
- This webpage has a redirect loop issue
- Trying to re-direct users to specific page based on an ACF variable
- WordPress site login Redirect
- Problem in auto login after registration
- WordPress Redirect After logging
- A way to redirect users when they log in based on their current page
- Remember me doesn’t work with www?
- Trim the repeated value in URL
- redirect not logged in users to specific page and redirect them back where they come from
- Login form- no feedback
- Can’t access wordpress mgt dashboard until propogation finished?
- Increase of failed login attempts, brute force attacks? [closed]
- Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
- wp_signon() does not authenticate user guidance needed
- How to pass users back and forth using session data?
- Avoid to load default WP styles in login screen
- Send reset password link to user from custom lost password form
- template_redirect to accompany with a shortcode
- How long do users stay logged in if they DON’T check remember me?
- How does WordPress track that a certain User is Logged-In
- 2 wordpress blogs with 1 users table and 1 login
- How can i add validation to this login form with out it redirecting to the wp-login.php page
- Bootstrap Modal as login page
- Custom login page always redirecting to wp-login.php
- Force users to register in order to view website [duplicate]
- auto login after registeration for wp-members plugin
- Passing username to login screen
- Sniffing wordpress user’s credentials
- v5.6.2 User cannot stay logged in – wordpress_test cookie placed but not auth cookies
- Redirect user to previous page after signup from custom form
- How to set JWT token with PHP on successful login?
- Facebook login for private group members
- WordPress error on log out ‘Not Permitted’ and can’t log out
- How can I change the email sender name from wordpress to (myblogname) on the “lost password” email?
- Changed primary domain and now wordpress login won’t work
- Add logout link when logged in, make it disappear when logged out?
- Keep user session with custom implementation of user login
- Forcing frontend login with UI switch
- Sidebar login widget with error print, returns an error
- Login without Password
- Exclude login page from custom maintenance code
- Temporarily locked out … how long is a “short while”?
- Change default login auth
- I can’t access my WordPress dashboard – shows Warning message [closed]
- Add html to wp_login_form
- Access log “POST /wp-login.php HTTP/1.0” 400
- Are login functions considered part of the WP backend?
- SQL – Remove All The Users and Create A New User With Admin Role Via PhpMyAdmin
- Can I protect a type of content site-wide with a single password?
- Sign in with social media accounts without creating a WP account [closed]
- WordPress login form script
- WordPress authentication using custom php?
- what is the best and safest way to allow users to register to site
- ERROR: Cookies are blocked due to unexpected output (no FTP access)
- Sharing a logged in session with a custom subdmain site?
- How do I change the language of the login page to Arabic?
- MAMP localhost wordpress site, not possible to sign in, username and password are correct
- Login issues wordpress page
- How to post frontend login form to a different authentication script from wp-login?
- Make WordPress User Name be the Company Name when Registering (not the default ‘first name’ last name’ email address’)
- Why do I have a reauth=1 redirection loop when I try to log in to WordPress hosted on AWS Fargate?
- Login form does not store/remember/suggest users password
- Problem with is_user_logged_in() function in some pages
- Confused – can’t access wordpress dashboard or site that has been published
- wordpress login loop and session problem
- unable to Login to Admin
- WordPress login loop on proxy setup with SSL – Apache proxy to IIS
- ERROR: Cookies are blocked due to unexpected output – ultimate solution
- How to dequeue the default CSS styles on the wp-login.php page?
- confirmation email is send from my local host registration of a user but mail will not display in there email account?
- Server error after log in
- How do I resolve my inability to login to WordPress dashboard? [duplicate]
- Chrome incorrectly displaying WP login as ‘not fully secure’
- Changed from HTTP to HTTP, can login no longer login
- Hide wp-login.php but not the widget
- Without user loging inner page is disable wordpress [duplicate]
- Registration and Login form
- WordPress and Magento: let WordPress manage user registration and logins?
- Share login status across subdomains without network
- How to change the login URL
- Click on banner to register to the blog
- Redirect drafted post of custom post type to URL?
- “user not registered” when trying to login and “There has been a critical error” message on site
- Cannot find redirect – WordPress behind HTTPS proxy (Cloudfront)
- Where does the redirect from shortlink to permalink happen?
- generate an array of user login date using update_user_meta();