To restrict direct access only for ‘wp-login.php’, without POST or GET request (useful for custom ajax login forms), I use the advanced function:
function possibly_redirect(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
if ( isset( $_POST['wp-submit'] ) || // in case of LOGIN
( isset($_GET['action']) && $_GET['action']=='logout') || // in case of LOGOUT
( isset($_GET['checkemail']) && $_GET['checkemail']=='confirm') || // in case of LOST PASSWORD
( isset($_GET['checkemail']) && $_GET['checkemail']=='registered') ) return; // in case of REGISTER
else wp_redirect( home_url() ); // or wp_redirect(home_url('/login'));
exit();
}
}
add_action('init','possibly_redirect');
Related Posts:
- Custom login form redirect to external site
- Clarification on auth_redirect()
- Redirect user after login/registration globally
- Remove lost password form and URL
- How to auto login after registration? [duplicate]
- Change ‘Back To Website’ link in wp-login.php
- Redirect away from login page
- Redirect when accessing /login when logged in
- Redirect outside WP after login
- wp_login_form redirect problem
- How to redirect wp_login_form to new page after user loged in?
- redirect doesn’t work while using example code
- Disable redirect to homepage after successful Login, Stay on Current Page
- wp_login_form() redirect same page
- Determine user destination on wp-login.php
- Redirect after login when WordPress in subdirectory
- Login redirects to home page and doesn’t log in
- Custom login-form redirect
- Login Form Redirection
- Redirect user to login and then to page where they came from
- How to force a 404 on WordPress
- WordPress redirecting connections on port 8080 to 80
- Disable ONLY URL auto complete, not the whole canonical URL system
- 301 redirect instead of 404 when URL is a prefix of a post or page name?
- Redirecting WordPress /.htaccess / HSTS / SSL
- How to create a php url redirection for nicer links
- Custom domain for sub-section of parent website
- WP redirects all pages from new domain to old domain
- wp_logout_url() redirects to confirmation page even with nonce?
- Redirecting old site links to new site
- Redirect after closing Theme Customizer when user does not have permission for theme page
- Creating intro page in wordpress
- Redirect to https not working with .htaccess [closed]
- How to redirect action=register link on the lostpassword page to a different link?
- You do not have sufficient permissions to access this page
- Perform a redirect after user action
- Redirect one of two domains on one WordPress installation
- WordPress site in subdirectory load site in main directory
- How do I redirect users after submitting a replies for moderation on bbpress?
- Redirect blogpage /blog/abcd/ to /blog/
- template_redirect causing infinite loop when get_queried_object is called
- Redirect all pages except one to homepage via .htaccess
- Does WP always makes 301 redirection?
- htaccess redirects and WordPress
- wp_redirect does not work
- Use virtual pages point to one specific page
- How to migrate production WordPress to Localhost
- Redirect first category archive page to normal page
- How to redirect a page into file?
- Check Page requested, and redirect
- WordPress on a local machine redirecting to xampp dashboard page [closed]
- Redirect all requested url to new url
- Can’t control WordPress Addresses from admin panel
- reducing number of URL Redirects and increasing speed
- This redirect loop is eating my lunch! [closed]
- What is this code in my theme’s footer.php causing chmod permission warnings? [closed]
- How to use https on one page only?
- WP not logging in at first time
- Problem in disabling canonical 301 redirect
- Prevent users from going to wordpress profile after login
- Why does the $_GET parameter ?search forward the front-page to the archive/blog page
- Keep subcategory grandson in slug
- Force WordPress https redirect before www redirect based on site address url
- Prevent wordpress autoredirect
- My site is being redirected to itself
- Permalinks do not include www subdomain
- Front page is being directed to an unknown site
- Redirect away from page if user is not admin
- Domain redirect to wp-admin/setup-config.php file
- redirect to a child theme based on the town of Internet users in france with the verification of the ip address
- Redirect to parent page if child does not exist
- Conditional Redirect
- Upload Directory question
- Redirect Page ID, based on logged-in User Role
- How can I stop redirecting from a search to a taxonomy archive page
- htaccess redirect not working for wp-admin/edit in site using proxy
- How to access my wordpress application using two URLs?
- Redirect Pending Review Status Preview page url to custom url
- Debugging issue with redirection in WordPress
- The / location 301-redirects to itself in a loop
- Better, more efficient redirecting
- Internal Redirections?
- WordPress website down with error “redirected you too many times.”
- Make custom post type archive for administrator only
- Using cache brokes redirecting
- Homepage (domain) that redirects user toward two subdomains based on his/her preferred language
- How to redirect new registrars to a custom registration page instead of WP default registration page?
- WordPress redirect users from certain countries to subpage of language version
- Unable to access WP test site
- Custom Login Plugin Redirects to wp-login.php After Site Migration
- Force SSL on a single page which is used as iFrame
- New clone of WordPress site 301 redirects back to orginal site
- Show page without reference to post (like front-page)
- How to redirect all pages of a blog to a new blog
- Remove link before another link
- WordPress as a Facebook app
- URL Custom Rewrite
- How to handle expired assets/content when user has direct URL
- Forcing header cache control in 404 pages
- Redirect certain 404 pages to parent page