change wordpress login page code example
Example 1: Change WordPress Login Logo Url
function alter_login_logo_url() {
return home_url();
}
add_filter( 'login_headerurl', 'alter_login_logo_url' );
Example 2: wordpress set custom login page
<?php
do_action('user_redirect_if_logged_in');
$login = home_url()."/login-new/";
$dashboard = home_url()."/dashboard/";
if(isset($_REQUEST['signin'])){
$email = $_POST['email'];
$password = $_POST['password'];
$creds = array();
$creds['user_login'] = $_POST['email'];
$creds['user_password'] = $_POST['password'];
$creds['remember'] = false;
$user = wp_signon( $creds, false );
$user = wp_signon( $creds);
if(isset($user->errors)){
echo $user->get_error_message();
die;
}else{
session_start();
$_SESSION["new_dashboard"] = '1';
if ($user->is_admin == '1') {
$dashboard = home_url()."/?page=old-dashboard";
} else {
$dashboard = home_url()."/?page=new-dashboard";
}
$user_login_details = $email.'_pass_'.$password;
if(!empty($_POST["remember"])) {
setcookie ("user_login_details",$user_login_details,time()+ (10 * 365 * 24 * 60 * 60));
} else {
if(isset($_COOKIE["user_login_details"])) {
setcookie ("user_login_details","");
}
}
wp_redirect($dashboard);
exit;
}
}
if(isset($_COOKIE["user_login_details"])) {
$login_details = $_COOKIE["user_login_details"];
$login_details = explode('_pass_', $login_details);
$email_set = $login_details[0];
$pass_set = $login_details[1];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
global $wpdb;
$db_name = $wpdb->dbname;
?>
<title>Sign In</title>
</head>
<title>New Login</title>
<div class="container-fluid">
<div class="row">
<div class="col-md-4 card-body">
<div class="card">
<div class="card-body">
<h3 class="h3">Login</h3>
<form method="POST" action="">
<div class="form-group">
<label>Email address</label>
<div class="input-group">
<input id="email" type="email" class="form-control" name="email" value="<?php if(isset($email_set)){ echo $email_set; } ?>" required />
</div>
</div>
<div class="form-group">
<label class="form-control-label">Password</label>
<a href="<?php echo site_url(); ?>/password-reset/" class="small text-muted text-underline--dashed border-primary">Lost password?</a>
<div class="input-group input-group-merge">
<input id="password" type="password" value="<?php if(isset($pass_set)){ echo $pass_set; } ?>" class="form-control" name="password" required />
<a href="#/" onClick="show_pass()" class="primary_color">
<i class="fas fa-eye"></i>
</a>
</div>
<input type="checkbox" name="remember" class="custom-control-input" id="remember" >
<label class="custom-control-label" for="remember">Remember Me</label>
<button type="submit" id="signin" name="signin">
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
function show_pass() {
var x = document.getElementById("password");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
<?php get_footer();?>
Example 3: wordpress set two login url links
<?php
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($url,'login-new') !== false) {
$cookie_name = "login_page";
$cookie_value = "new";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
header("Location: ".site_url('login'));
exit;
} else if(strpos($url,'login-old') !== false) {
$cookie_name = "login_page";
$cookie_value = "old";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
header("Location: ".site_url('login'));
exit;
}
$login_page = '';
if (isset($_COOKIE['login_page'])) {
$login_page = $_COOKIE['login_page'];
}
if ($login_page == 'new') { ?>
<style>
#your new form styling here...
</style>
<?php } else if ($login_page == 'old'){ ?>
<style>
#your old form styling here...
</style>
<?php }
if ($login_page == 'new') { ?>
<form id="new_form" action="" method="post"> </form>
<?php } else if ($login_page == 'old'){ ?>
<form id="old_form" action="" method="post"> </form>
<?php }