Last updated on September 14, 2023

Disable WordPress Password Strength Meter

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Simplify registration; disable password strength.

The WordPress password strength meter is a feature that provides feedback to users when they are creating or updating their passwords. However, in some cases, you may want to disable this feature. This can be useful if you have implemented your own password strength validation or if you simply prefer not to show the password strength meter to your users.

To disable the WordPress password strength meter, you can use the wp_localize_script() function to modify the user-profile.js script that is responsible for handling the password strength meter.

Here’s an example code snippet that disables the password strength meter:

function wpsnippets_disable_password_strength_meter() {
    wp_enqueue_script( 'user-profile' );
    wp_localize_script( 'user-profile', 'userProfileL10n', array(
        'passwordHint' => '',
    ) );
}
add_action( 'admin_enqueue_scripts', 'wpsnippets_disable_password_strength_meter' );

In this code snippet, we use the wp_enqueue_script() function to enqueue the user-profile script, which contains the password strength meter functionality. Then, we use the wp_localize_script() function to modify the userProfileL10n object, which is used to pass localization data to the script. By setting the passwordHint property to an empty string, we effectively disable the password strength meter.

You can add this code snippet to your theme’s functions.php file or in a custom plugin. Once added, the password strength meter will no longer be displayed on the user profile page in the WordPress admin area.

This code snippet can be useful in situations where you want to customize the password strength validation or if you prefer not to show the password strength meter to your users.

Examples

Example 1: Disabling the Password Strength Meter using a Plugin

This example demonstrates how to disable the WordPress password strength meter by using a custom plugin.

<?php
/**
 * Plugin Name: Disable Password Strength Meter
 * Plugin URI: https://example.com/
 * Description: Disables the password strength meter in WordPress.
 * Version: 1.0
 * Author: Your Name
 * Author URI: https://example.com/
 * License: GPL2
 */

add_action( 'wp_print_scripts', 'wpsnippets_disable_password_strength_meter', 100 );

function wpsnippets_disable_password_strength_meter() {
    wp_dequeue_script( 'password-strength-meter' );
}

In this code example, we create a custom plugin that disables the password strength meter in WordPress. We use the wp_print_scripts action hook to dequeue the password-strength-meter script, effectively preventing it from being loaded on the front-end.

Example 2: Disabling the Password Strength Meter using a Theme’s functions.php file

This example demonstrates how to disable the WordPress password strength meter by adding code to the functions.php file of your theme.

<?php
// functions.php

function wpsnippets_disable_password_strength_meter() {
    wp_dequeue_script( 'password-strength-meter' );
}
add_action( 'wp_print_scripts', 'wpsnippets_disable_password_strength_meter', 100 );

In this code example, we add the wpsnippets_disable_password_strength_meter function to the functions.php file of our theme. This function dequeues the password-strength-meter script using the wp_print_scripts action hook, effectively disabling the password strength meter.

Example 3: Disabling the Password Strength Meter using a Custom Plugin with a Conditional Check

This example demonstrates how to disable the WordPress password strength meter conditionally, based on user roles, by using a custom plugin.

<?php
/**
 * Plugin Name: Disable Password Strength Meter for Subscribers
 * Plugin URI: https://example.com/
 * Description: Disables the password strength meter for subscribers in WordPress.
 * Version: 1.0
 * Author: Your Name
 * Author URI: https://example.com/
 * License: GPL2
 */

add_action( 'wp_print_scripts', 'wpsnippets_disable_password_strength_meter', 100 );

function wpsnippets_disable_password_strength_meter() {
    if ( current_user_can( 'subscriber' ) ) {
        wp_dequeue_script( 'password-strength-meter' );
    }
}

In this code example, we create a custom plugin that disables the password strength meter for subscribers in WordPress. We use the wp_print_scripts action hook and a conditional check (current_user_can) to dequeue the password-strength-meter script only for users with the “subscriber” role. This allows us to selectively disable the password strength meter based on user roles.

Last updated on September 14, 2023. Originally posted on September 17, 2023.

Leave a Reply

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