Skip to content

Instantly share code, notes, and snippets.

@mojenmojen
Created March 1, 2017 19:13
Show Gist options
  • Save mojenmojen/ef3b81979489e90b1a9be833b91b49e1 to your computer and use it in GitHub Desktop.
Save mojenmojen/ef3b81979489e90b1a9be833b91b49e1 to your computer and use it in GitHub Desktop.
Wordpress Login Redirect to Custom Page
/* Main redirection of the default login page */
function qs_redirect_login_page() {
$login_page = home_url('login');
$page_viewed = basename($_SERVER['REQUEST_URI']);
if($page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
wp_redirect($login_page);
exit;
}
}
add_action('init','qs_redirect_login_page');
/* Where to go if a login failed */
function qs_custom_login_failed() {
$login_page = home_url('login');
wp_redirect($login_page . '?login=failed');
exit;
}
add_action('wp_login_failed', 'qs_custom_login_failed');
/* Where to go if any of the fields were empty */
function qs_verify_user_pass($user, $username, $password) {
$login_page = home_url('login');
if($username == "" || $password == "") {
wp_redirect($login_page . "?login=empty");
exit;
}
}
add_filter('authenticate', 'qs_verify_user_pass', 1, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment