I do this the same, but a little differently, and handle the case of logging in regular users or admins. I will assume you know to put these sorts of things in your “functions.php” or equivalent.
add_filter('login_url', 'your_login_url', 10, 2 );
add_action('login_init', 'your_login_page');
add_action('wp_login', 'your_login_redirect', 10, 2);
// assuming that your new front end login url is "/login", use these:
function your_login_url($login_url, $redirect) {
return home_url('/login/');
}
function your_login_page() {
wp_redirect(home_url('/login/'), 302);
}
// if admin send them to the dashboard, otherwise leave them on the frontend
function your_login_redirect($user_login, $user) {
if (current_user_can('activate_plugins')) {
wp_redirect('/wp-admin/index.php', 302);
exit();
}
}
Finally, if you’re feeling like you want to handle password resets on the front end (the actual code for handling this is a bit more involved) here is the filter you can use:
add_filter('lostpassword_url', 'your_lost_password_page', 10, 2);
You would have to send a reset email with a one time use link after collecting the users email address via a form, and then provide for verification of that link, and another form to allow the user to reset their password. (and probably verify the text). Each of those pages will need some sort of response messaging also.