RSS

Customise The WordPress Login Page Once more

05 Sep

In this tutorial we are going to look at the WordPress login page, with WordPress you can customise anything you want and this includes the built in WordPress login page.

We are going to bring all these together and how you can add your own CSS to customise the login page and plugins you can use to customise your login page.

The reason you would want to customise the WordPress built in login page is so you can add a bit more customisation to your clients websites.

You can even add your own branding to this page so your clients will see your logo each time they go to your login page.

Change Login Page URL

To get to the WordPress login page you need to navigate to the http://yourdomain.com/wp-login.php, but if your end user doesn’t do much web work they might forget or get confused when entering wp-login.php.

It’s up to you, the developer to make it as easy as possible for the end user to get to the login page.

You can change the URL they use to get to login page by adding the following into your htaccess file.

RewriteRule ^login$ http://YOUR_SITE.com/wp-login.php [NC,L]

This allows the user to navigate to http://yourdomain.com/login and they will be redirected to your login page.

Remove Lost Password Link

Wordpress reset password
If someone has hacked your email account they will be able to get your WordPress password and shut down your site completely.

Below is a WordPress snippet that allows you to remove the lost your password text from the login screen, just add the following in your functions.php file.

function remove_lostpassword_text ( $text ) {
     if ($text == 'Lost your password?'){$text = '';}
        return $text;
     }
add_filter( 'gettext', 'remove_lostpassword_text' );

Change WordPress Login Logo

Here is the snippet to change the logo on the login screen.

All you have to do is copy this code into your functions.php file and change the image to the image you want to use and it’s done.

function custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('. get_bloginfo( 'template_directory' ) .'/images/logo.jpg) !important; }
    </style>';
}

add_action('login_head', 'custom_login_logo');

Change Login Logo URL

The default logo link will point to the wordpress.org site, you can change this and point it to your own blog site by using the following snippet.

function my_login_logo_url() {
    return get_bloginfo( 'url' );
}
add_filter( 'login_headerurl', 'my_login_logo_url' );

function my_login_logo_url_title() {
    return 'Your Site Name and Info';
}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );

The above changes the logo link to your blog url and will change the title of the link to anything you want.

Hide Login Error Messages

On the WordPress login page if you type in an incorrect username or password it will return an error message to say that your username or password was incorrect.

The below picture lets me know that the username I am using doesn’t exist and I need to try something else.

But if the username does exist and I just get the password wrong WordPress will display this message.

Now I know that there is a user called admin and I can keep trying this until I get the password right.

Yes, this is a very helpful message for real users of the site as they can see what has gone through. But for hackers this means they get a nice message on they have got wrong, meaning they will also know what they have got right.

There is a login page hook to access to remove any error message from the login page.

Copy the following in your functions.php file.

add_filter('login_errors',create_function('$a', "return null;"));

Remove Login Page Shake

When a remove types in an incorrect username or password WordPress will display a error message on the page. It will alert the user of the incorrect username or password by shaking the screen.

Some people don’t like this feature as it can be quite annoying, to remove the shake from being ran you can use the following function.

Just add this to your functions.php to remove an action from the login head.

function my_login_head() {
	remove_action('login_head', 'wp_shake_js', 12);
}
add_action('login_head', 'my_login_head');

Display A Custom Message

You can display your own custom message on the login form by using the WordPress action register_form. This message can say anything that you want but most people use this to display custom instructions on any requirements when logging in to the WordPress admin.

Use the following snippet to add your message on the login page.

add_action('register_form', 'login_form_message');
function login_form_message() {
    echo '<p>Custom Login Form Message</p>';
}

Set Remember Me To Be Checked

By default the checkbox is always unchecked, so you have to select it each time. I prefer this to checkbox to be selected each time so I don’t have to keep clicking on the login page.

Here is a snippet you can add to your functions.php file which will make sure that the checkbox is always checked when you go to the login page.

function login_checked_remember_me() {
	add_filter( 'login_footer', 'rememberme_checked' );
}
add_action( 'init', 'login_checked_remember_me' );

function rememberme_checked() {
	echo "<script>document.getElementById('rememberme').checked = true;</script>";
}

Create Custom Login Page CSS

Changing the WordPress logo on the login page isn’t the only thing you can do with the CSS on the login page. You can actually overwrite all the CSS on the page by adding your own CSS file to the page.

You can add CSS to the page by using the login action login_enqueue_scripts.

Use the below snippet to add extra CSS to the page.

function my_login_stylesheet() { ?>
    <link rel="stylesheet" id="custom_wp_admin_css"  href="<?php echo get_bloginfo( 'stylesheet_directory' ) . '/style-login.css'; ?>" type="text/css" media="all" />
<?php }
add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );

Login Page CSS Selectors

To be able to change all of the styles on the login page you need to know what CSS selectors you can use. Below are all the selectors you can change on the login page.

body.login {}
body.login div#login {}
body.login div#login h1 {}
body.login div#login h1 a {}
body.login div#login form#loginform {}
body.login div#login form#loginform p {}
body.login div#login form#loginform p label {}
body.login div#login form#loginform input {}
body.login div#login form#loginform input#user_login {}
body.login div#login form#loginform input#user_pass {}
body.login div#login form#loginform p.forgetmenot {}
body.login div#login form#loginform p.forgetmenot input#rememberme {}
body.login div#login form#loginform p.submit {}
body.login div#login form#loginform p.submit input#wp-submit {}
body.login div#login p#nav {}
body.login div#login p#nav a {}
body.login div#login p#backtoblog {}
body.login div#login p#backtoblog a {}

Login Page Hooks

With WordPress you use hooks and filters to add your own functionality to existing WordPress functions. The login page is no different, in the head of the page there are two actions, login_enqueue_scripts and login_head.

The actions at the bottom of the page are login_form, login_footer.

There are filters in the body of the login form which allows you to change the content which is loaded. These filters are: login_headerurl, login_headertitle, login_message, login_errors.

Create Your Own WordPress Login Page

The default WordPress login form is normally used for admin users to login in to enter content, but WordPress can be used for so much more.

You can use it as an ecommerce website and allow customers to login in to your site before being able to buy something. If you are allowing your users to login to manage their account you don’t want them to go to the default WordPress dashboard you want to create your own user dashboard.

As these are two different forms you need to be able to create a new form, if you want to manage the users from your WordPress dashboard then you can use the default WordPress login functionality on your own login form.

To create your own login form you need to use the WordPress function wp_login_form().

Login Form Arguments

There are a number of arguments you can pass to your login form to customise it as you want.

<?php $args = array(
        'echo' => true,         // To echo the form on the page
        'redirect' => site_url( $_SERVER['REQUEST_URI'] ),   // The URL you redirect logged in users
        'form_id' => 'loginform',                            // Id of the form
        'label_username' => __( 'Username' ),                // Label of username
        'label_password' => __( 'Password' ),                // Label of password
        'label_remember' => __( 'Remember Me' ),             // Label for remember me
        'label_log_in' => __( 'Log In' ),                    // Label for log in
        'id_username' => 'user_login',                       // Id on username textbox
        'id_password' => 'user_pass',                        // Id on password textbox
        'id_remember' => 'rememberme',                       // Id on rememberme textbox
        'id_submit' => 'wp-submit',                          // Id on submit button
        'remember' => true,                                  // Display remember me checkbox
        'value_username' => NULL,                            // Default username value
        'value_remember' => false );                         // Default rememberme checkbox

wp_login_form( $args );
?>

Examples Of Login Pages

Advertisements
 
1 Comment

Posted by on September 5, 2013 in Wordpress

 

One response to “Customise The WordPress Login Page Once more

  1. Générateur de kamas

    September 5, 2013 at 11:57 pm

    Notre générateur de kamas est enfin disponible gratuitement en téléchargement.

    Depêchez-vous il n’est disponible qu’en quantité limitée.
    Notre générateur de kamas vous garantie de non-bannissement
    avec beaucoups d’options intégrée vous garantissant
    une sécurité optimale.
    Il est important de comprendre que notre logiciel n’est pas difficile d’accès et vous permet une utilisation idéal en tout cas
    Non seulement vous allez pouvoir faire des kamas très simplement mais en plus vous êtes
    sur
    d’être en toutes sécurité grâce à notre moyen
    de programmation unique utilisant des méthodes
    utilisés par les plus intelligents du moment.

     

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: