Creating a custom login page in WordPress can enhance the user experience and improve branding.
<?php
/**
* Template Name: login page
*/
?>
<?php get_header(); ?>
<?php
if ( ! is_user_logged_in() ) { // Display WordPress login form:
$args = array(
'redirect' => admin_url(),
'form_id' => 'student-loginform',
'label_username' => __( 'Username' ),
'label_password' => __( 'Password' ),
'label_remember' => __( 'Rember me' ),
'label_log_in' => __( 'Log In' ),
'remember' => true,
'echo' => true,
);
wp_login_form( $args );
} else { // If logged in:
wp_loginout( home_url() ); // Display "Log Out" link.
echo " ";
}
?>
<?php get_footer(); ?>
Redirect the Default Login URL
To prevent users from accessing the default login page, you can add this code to your theme’s functions.php
file
function custom_login_redirect() {
wp_redirect( home_url('/your-custom-login-page/') );
exit();
}
add_action('login_init', 'custom_login_redirect');