In this tutorial, We will go over some WordPress Login Page Tweaks.
1) Add Custom Text to WordPress Login Page
What if you want user to see custom message before logging in? Wanted to highlight any special event? Well, there is a very easy tips. Just add below to your functions.php
file and you should be all set.
// Add Message to Login Screen function crunchify_login_message( $message ) { if ( empty($message) ){ return "<p class='message'>Crunchify Tips: Welcome. Please Log-In to Continue..<br><br>Don't forget to checkout new admin panel after login :)</p>"; } else { return $message; } } add_filter( 'login_message', 'crunchify_login_message' );
2) Remove Login Shake Effect when Error Occurs
What if you want to remove Login Shake Error Effect? Just add below code to functions.php
file and you are all set.
function crunchify_remove_login_shake_effect() { remove_action('login_head', 'wp_shake_js', 12); } add_action('login_head', 'crunchify_remove_login_shake_effect');
3) Add Login / Logout button to WordPress Menu bar
add_filter('wp_nav_menu_items', 'crunchify_add_login_logout_menu', 10, 2); function crunchify_add_login_logout_menu($items, $args) { ob_start(); wp_loginout('index.php'); $loginoutlink = ob_get_contents(); ob_end_clean(); $items .= '<li style=" float: right;">'. $loginoutlink .'</li>'; return $items; }
Here is in-depth tutorial on Login/Logout Menu.
4) How to Redirect WordPress back to referring page after successful Login?
What if you want to redirect your users to referral URL after successful login attempt?
There is a simple tweak for it. Just use below code snippet for the same.
if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) { add_filter('login_redirect', 'crunchify_login_redirect', 10, 3); function crunchify_login_redirect() { $location = $_SERVER['HTTP_REFERER']; wp_safe_redirect($location); exit(); } }
5) Add Email Address as a login Criteria
function crunchify_add_email_address($username) { $user = get_user_by('email',$username); if(!empty($user->user_login)) $username = $user->user_login; return $username; } add_action('wp_authenticate','crunchify_add_email_address'); function crunchify_change_text_on_login_form($text){ if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){ if ($text == 'Username'){$text = 'Username / Email Address';} } return $text; } add_filter( 'gettext', 'crunchify_change_text_on_login_form' );
If you have any other tips and wanted to share then please update in comment section below.