How to Create a Custom Login Page in WordPress Without a Plugin – 2024

Creating a New Separate Custom WordPress Login Page

Creating a custom login page for your WordPress site can provide a unique experience for your users. Follow these steps to set up a custom login page without using any plugins.

Step 1: Create a Custom Page Template

First, create a custom page template in your theme’s directory.

  1. Open your theme’s folder (usually located in wp-content/themes/your-theme-name).
  2. Create a new file and name it custom-login.php.
  3. Open custom-login.php and add the following code to define it as a custom page template:
				
					<?php
/* Template Name: Custom Login */
get_header();
?>

<!-- The rest of your code will go here -->

<?php get_footer(); ?>

				
			

Step 2: Create the Login Form

Next, create the HTML for the login form. Add this code after the get_header(); line:

				
					<div class="login-form-container">
    <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
        <p>
            <label for="user_login">Username<br />
            <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
        </p>
        <p>
            <label for="user_pass">Password<br />
            <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
        </p>
        <p class="forgetmenot">
            <label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember Me</label>
        </p>
        <p class="submit">
            <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In" />
            <input type="hidden" name="redirect_to" value="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" />
        </p>
    </form>
</div>

				
			

Step 3: Create a New Page

With your custom page template ready, create a new page in WordPress.

  1. In your WordPress dashboard, go to Pages > Add New.
  2. Give your page a title, such as “Custom Login”.
  3. In the ‘Page Attributes’ section, select your ‘Custom Login’ template from the ‘Template’ dropdown menu.
  4. Publish your page.
				
					<?php
/* Template Name: Custom Login */
get_header();
?>

<div class="login-form-container">
    <form name="loginform" id="loginform" action="<?php echo site_url( '/wp-login.php' ); ?>" method="post">
        <p>
            <label for="user_login">Username<br />
            <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
        </p>
        <p>
            <label for="user_pass">Password<br />
            <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
        </p>
        <p class="forgetmenot">
            <label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember Me</label>
        </p>
        <p class="submit">
            <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In" />
            <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
        </p>
    </form>
</div>

<?php get_footer(); ?>

				
			

Optional Step: Redirect the Default Login Page to Your Custom Login Page

If you want to ensure users are directed to your custom login page instead of the default WordPress login page, you can add a redirect. Follow these steps to implement the redirect:

  1. Open your theme’s functions.php file (usually located in wp-content/themes/your-theme-name/functions.php).
  2. Add the following code to redirect the default login page to your custom login page:
 
				
					add_action('login_enqueue_scripts', 'custom_login_page_redirect');
function custom_login_page_redirect() {
    wp_redirect(site_url('/custom-login/'));
    exit();
}

				
			

Replace '/custom-login/' with the slug of your custom login page.

Full Implementation with Redirection

Here’s how you can set up the entire process from start to finish:

Step 1: Create a Custom Page Template

  1. Create a new file named custom-login.php in your theme’s directory (wp-content/themes/your-theme-name).

  2. Open custom-login.php and add the following code:

				
					<?php
/* Template Name: Custom Login */
get_header();
?>

<div class="login-form-container">
    <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
        <p>
            <label for="user_login">Username<br />
            <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
        </p>
        <p>
            <label for="user_pass">Password<br />
            <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
        </p>
        <p class="forgetmenot">
            <label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember Me</label>
        </p>
        <p class="submit">
            <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In" />
            <input type="hidden" name="redirect_to" value="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" />
        </p>
    </form>
</div>

<?php get_footer(); ?>

				
			

Step 2: Create a New Page

  1. In your WordPress dashboard, go to Pages > Add New.
  2. Give your page a title, such as “Custom Login”.
  3. In the ‘Page Attributes’ section, select your ‘Custom Login’ template from the ‘Template’ dropdown menu.
  4. Publish your page.

Step 3: Redirect Default Login Page

  1. Open your theme’s functions.php file.
  2. Add the following code to redirect the default login page to your custom login page:
				
					add_action('login_enqueue_scripts', 'custom_login_page_redirect');
function custom_login_page_redirect() {
    wp_redirect(site_url('/custom-login/'));
    exit();
}

				
			

Replace '/custom-login/' with the slug of your custom login page.

With these steps, any attempts to access the default login page (/wp-login.php) will be redirected to your custom login page. This method ensures that users experience a consistent login interface tailored to your site.

By following this guide, you can successfully create a custom login page in WordPress and optionally redirect users from the default login page. Feel free to customize the appearance and functionality to suit your needs.

Table of Contents

Start Bulk Creating Pages in WordPress
Need to boost your sEO?
Start bulk creating Pages Today with LPagery!
Pro Feature

When to Use This Feature

Use Examples