How to Remove the Login Shake Effect When an Error Occurs in WordPress

Home » Snippets » How to Remove the Login Shake Effect When an Error Occurs in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Ever experienced your login page shaking whenever you make a mistake trying to access your WordPress website? This shaking effect is a WordPress feature designed to alert users to login errors. While it’s intended to be helpful, not everyone appreciates the feature, finding it more annoying than useful. The good news is that removing the login shake effect is entirely doable. In this article, we will guide you through the necessary steps to disable this shake effect, to make your login process more straightforward and streamlined.

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

The code snippet begins by defining a new function named ‘wpturbo_remove_login_shake()’. The purpose of this function is to remove the shake effect that WordPress displays when a login error occurs.

First, let’s understand what the ‘shake’ effect is. When you enter incorrect login details in the WordPress login form, your screen makes a ‘shake’ movement which indicates that an error occurred. Some developers might find this effect unnecessary or irritating and may want to remove it. This is where our function comes into play.

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

In the function defined above, we use the ‘remove_action()’ function provided by WordPress. As the name suggests, the ‘remove_action()’ function is used to remove a previously registered action function. When we call ‘remove_action()’, we must pass in exactly the same parameters as when the function was added.

The first parameter passed is ‘login_head’, which is the action hook from which we want to remove the function. This hook is triggered in the head section of the login page in WordPress.

The second parameter is ‘wp_shake_js’, which is the name of the function we want to remove from the specified hook. This is the core WordPress function responsible for including the ‘shake’ script on the login page.

The last parameter is ’12’. This indicates the priority of the function we want to remove. When the function was originally added, it was assigned a priority of ’12’. When removing it, we need to specify the exact same priority.

add_action('login_head', 'wpturbo_remove_login_shake');

The last line of the code snippet is calling ‘add_action()’, which is used to connect (‘hook’) our just defined ‘wpturbo_remove_login_shake()’ function to ‘login_head’ action hook. This means, every time ‘login_head’ hook runs, it will also run our ‘wpturbo_remove_login_shake()’ function. In this function, we have removed the ‘shake’ effect, hence effectively disabling the shaking effect on the WordPress login page.

Register an account to save your snippets or go Pro to get more features.