How to Create a Custom Login Page in WordPress?

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');

administrator

Leave a Reply

Your email address will not be published. Required fields are marked *