0

I have created a custom page for login/registration. Is there any automated way to redirect all wp-login.php calls to that page, or will I need to replace all links manually.

For example, on the comments form, I have this default message:

You must be logged in to post a comment.

The logged in links to the

http://localhost/wp-login.php?redirect_to=url

How can I change this to:

http://localhost/my-custom-login-page

1 Answer 1

0

You can redirect requests to wp-login.php to your page:

add_action(
  'login_head',
  function() {
    $parsed = parse_url($_SERVER['REQUEST_URI']);
    $redirect = site_url('mypage');
    if (!empty($parsed['query'])) {
      $redirect .= '?'.$parsed['query'];
    }
    wp_safe_redirect($redirect,301);
    exit;
  }
);

However, wp-login.php appears ~34 times in Core on my 3.6.1 install ( grep -Rn "wp-login.php" * | wc -l ), and many of those do not appear to be filterable. Actually altering all of those links would take some work and may well involve core hacks.

The login_url filter, and the logout_url one, will get you part way, but it do not cover all cases.

add_action(
  'login_url',
  function($url) {
    return str_replace('wp-login.php','mypage',$url);
  }
);

Very rough code. Barely tested. Possibly buggy. Caveat emptor. No refunds.

Your Answer

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

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