0

Trying to change Wordpress login URL to an external Wordpress installation login page. I'm using the code below, but it can only redirect to a page or URL within the same site. I want it to redirect to an external Wordpress login URL. Any suggestions?

Thanks for your assistance!

// REDIRECT THE DEFAULT WORDPRESS LOGIN PAGE
// =============================================================
add_action('init','custom_login');
function custom_login(){
 global $pagenow;
 //  URL for the HomePage. You can set this to the URL of any page you wish to redirect to.
 $blogHomePage = get_bloginfo('url');
 //  Redirect to the Homepage, if it is login page. Make sure it is not called to logout or for lost password feature
 if( 'wp-login.php' == $pagenow && $_GET['action']!="logout" && $_GET['action']!="lostpassword") {
     wp_redirect('/login/');
     exit();
 }
}
  • change wp_redirect('/login/'); to wp_redirect('http://example.com'); – Mayeenul Islam Feb 14 at 19:22
  • You can wp_redirect() to an external site - just put in the full URL - but that won't actually let the user come back to the first site as logged in. For that you'll have to delve into the world of sharing cookies. It might be easier to use a single-sign-on plugin for both sites instead - that way once you log in you can get to either site. – WebElaine Feb 14 at 19:23
  • Thanks! I have tried changing the "wp_redirect" to a full URL path but is still not working so I thought something was wrong with the code. Just came to mind now to restart Apache and MySQL and see if it will work after that. I have also already have the session sharing done, so all I'm working on is the single sin on page. – P. Paul Feb 14 at 22:24
0

Not enough info to know if this is a possible solution for you but you might try to use the Wordpress.com login via JetPack plugin. It allows one login for all your WP websites. There are many other plugins that could do the job if logging into two sites at once is your goal, and the benefit is that you won't have to re-code your core or theme files with every update.

  • Hi! I'm not really looking into using jetpack. :) Thanks for the suggestion! – P. Paul Feb 14 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.