Change the password strength meter labels

A while ago I wrote a post about how to remove the password strength meter from the Checkout page. Since I strongly encourage you to not remove it though, like mentioned in that article as well, just changing the meter labels to something easier to understand can help instead!

By changing the meter labels you can explain what could be wrong with the password used, even if that would be hard since the script uses a 3rd-party tool to check the strength of a password which does not only check its length, presence of specific characters, numbers or signs.

You can read more about how it works on WP Tavern.

Probably you already understood that the password strength meter script is not from WooCommerce, so we have to change the meter labels in WordPress directly.

There’s a way to do it, you need to re-localize the script in your theme.
Since the theme is loaded after the core of WordPress, the new localization will load after the one in the core, and this last one will be used instead.

Open your functions.php file located in wp-content/themes/your-child-theme-name/ and add this code at the end of it:

add_action( 'wp_enqueue_scripts', 'my_strength_meter_localize_script' );
function my_strength_meter_localize_script() {
wp_localize_script( 'password-strength-meter', 'pwsL10n', array(
'empty' => __( 'But… it\'s empty!', 'theme-domain' ),
'short' => __( 'Too short!', 'theme-domain' ),
'bad' => __( 'Not even close!', 'theme-domain' ),
'good' => __( 'You are getting closer…', 'theme-domain' ),
'strong' => __( 'Now, that\'s a password!', 'theme-domain' ),
'mismatch' => __( 'They are completely different, come on!', 'theme-domain' )
) );

view raw


hosted with ❤ by GitHub

Now these new meter labels will be used instead of the core meter labels. They will be used everywhere the password strength meter is used, so in the edit user screen in the Dashboard, in the My Account page if the registration form is enabled and on the checkout page as well.

Update 23rd Feb. 2016: You can change also the default messages returned by WooCommerce. To do so, use this code:

add_filter( 'woocommerce_get_script_data', 'my_strength_meter_custom_strings', 10, 2 );
function my_strength_meter_custom_strings( $data, $handle ) {
if ( 'wc-password-strength-meter' === $handle ) {
$data_new = array(
'i18n_password_error' => esc_attr__( 'Come on, enter a stronger password.', 'theme-domain' ),
'i18n_password_hint' => esc_attr__( 'The password should be at least seven characters long.', 'theme-domain' )
$data = array_merge( $data, $data_new );
return $data;

view raw


hosted with ❤ by GitHub

Update 12th Feb. 2018: The code above only works from WooCommerce 3.3+. If you are running an older version of WooCommerce you should use this script instead.

36 replies
  1. Nick
    Nick says:

    Is it possible to adjust the actual strength requirements, e.g. the number of required characters, whether numerals/special characters are needed? – I’ve been having customers that are battling the strength meter. It was costing sales so I temporarily disabled it… But I don’t want it removed for the long term.

  2. Ashish
    Ashish says:

    Sir, the above code is gor what because the previous code is well it removes the strong validation but doesn’t suggest to keep strong password. If the above code purpose is to show alert messages to keep strong password with the previous code then it doesn’t work at all.
    So please tell how to add recommendation message for user to keep strong password with previous snippets

  3. Uttara
    Uttara says:

    I tried doing the same and now I’m getting this error

    Parse error: syntax error, unexpected end of file in /home/soulpuresoaps/public_html/wp-content/themes/azera-shop/functions.php on line 726

    Im a new with WordPress and now I’m completely clueless.

    • Nicola Mustone
      Nicola Mustone says:

      Hi Uttara,
      Sorry for the delay, I don’t know how I missed your comment.

      That error means that you added the code in the wrong location probably.

      If you file ends with ?> make sure to write the code before that sign.

  4. Derek Scambler
    Derek Scambler says:

    Hi Nicola, is there a way to determine when the password hint will appear? I have used your code from another post that has allowed me to reduce the minimum strength rating down to a rating of 1 instead of the default 3 but the hint still appears when the user is good to go on a weak password. It disappears when you hit medium strength but would like it to go on weak. Thanks!

  5. Eric
    Eric says:

    Thank you so much for this code!! I have no formal training in coding at all and have been learning to piece together my business’ website with tutorials like these. I still cannot figure out how to access the .php files for the life of me, but even better, I used the WordPress plugin “Snippets” and it all worked instantly. I had even tried the two WooCommerce account apps beforehand, and each one had major shortcomings this code fixes instantly. Also, if anyone is wondering, you can set the password slot to accept weak passwords (but still reject very weak ones) by setting the value in the code snippet linked above to .5.

    • Nicola Mustone
      Nicola Mustone says:

      Hi Eric,
      Thanks for sharing your thoughts!

      To access PHP files, you can login into your site via FTP. If you don’t know how to do this it would be better to check with your host. Most of them have tutorials about how to use FTP with them.

  6. Sandy Stark
    Sandy Stark says:

    I used this fabulous code on my WooCommerce site and it has worked for over a year, but I updated to WooCommerce 3.3 on a staging copy and started getting error “Warning: array_merge(): Argument #1 is not an array in /home/simpl131/staging/1/wp-content/themes/DiviChild_SCS/functions.php on line 136”

    Line 136 is this code “return array_merge( $data, $data_new );”

    I tried looking at the WooCommerce change log and I am not savvy enough to figure it out what changed. So, I am hoping you have some insight or I will just have to remove the code. Thank you!

  7. Derek Scambler
    Derek Scambler says:

    The same issue as Sandy has mentioned above has just happened to me too after my site was automatically updated by my server. Any help resolving this would be much appreciated.

  8. Jorge
    Jorge says:

    I have the same issue that Sandy and Derek mentioned before. Any solution for the “return array_merge( $data, $data_new );”.

  9. R
    R says:

    Just wondering if anyone found a solution to the “array_merge(): Argument #1 is not an array” issue with the latest version of Woo.

  10. Adina
    Adina says:

    Thank you – exactly what I’m looking for! 2 question: For the first code snippet, I see 2 javascript variables named pwsL10n on the page – and the code is using the first default woocommerce one – so this is not working. The second hook woocommerce_get_script_data does not seem to working at all for me – could it be because I am using the wp_print_scripts filter to enqueue the wc-password-strength-meter.js file?

    • Nicola Mustone
      Nicola Mustone says:

      Hi Adina,

      For the first code snippet, I see 2 javascript variables named pwsL10n on the page – and the code is using the first default woocommerce one – so this is not working

      I don’t understand what you mean. What page are you talking about?

      The second hook woocommerce_get_script_data does not seem to working at all for me – could it be because I am using the wp_print_scripts filter to enqueue the wc-password-strength-meter.js file?

      Maybe, I’m not sure. Try to disable your snippet and see if just with mine it works.

  11. Scott Moyse
    Scott Moyse says:

    THANK YOU!! The Warning: array_merge(): Argument #1 was proving tricky to pin down. There was zero documentation about it on any of the Woocommerce resources… do you know what the numbers represent at the end of this code? I feel like the first one may be the position in the woocommerce_get_script_data array, but not sure what the 2 represents.

    add_filter( ‘woocommerce_get_script_data’, ‘my_strength_meter_custom_strings’, 10, 2 );


Trackbacks & Pingbacks

  1. […] Update 16th Feb. 2016: Do you want to change only its labels? Check this post! […]

  2. […] Mustone posted a tutorial on changing the WordPress password strength meter messages, which is helpful for WooCommerce […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply