I'm looking for add a password generator with 14 characters on the protected pages like in the picture. I search something like what is used when you create users but for page password.

enter image description here

1 Answer 1


It is not possible to modify the post submit meta boxes with a filter.

But you can do that with JavaScript. This script will generate 10-12 random alphanumeric string and put it in the password field (if it is empty) when you click the Password protected radio button.

$('#visibility-radio-password').click(function () {
    // If there is no password
    var $password = $('#post_password')
    if ( !$password.val() ) {

Here you can learn how to correctly add JS scripts to admin pages - https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

  • Thanks. I add your code on file called admin.js and put it on folder called JS . I also put this code on function.php : add_action('admin_init', 'custom_admin_js'); function custom_admin_js() { wp_register_script( 'admin-js', get_stylesheet_directory_uri() . '/js/admin.js' ); wp_enqueue_script( 'admin-js' ); } . But it does not work . any idea?
    – Samuel
    Nov 29, 2017 at 12:00
  • Change the admin_init hook to admin_enqueue_scripts. And as 3rd parameter of wp_register_script add array('jquery') as this script depends on it.
    – Greg36
    Nov 29, 2017 at 12:08
  • Is it possible for you to put the correct full code? Thanks a lot
    – Samuel
    Nov 29, 2017 at 12:17
  • Your admin.js file should look like this: pastebin.com/31BvVSEt And in functions.php you should have this included: pastebin.com/8jxBs5PL
    – Greg36
    Nov 29, 2017 at 12:44
  • Thanks a lot Greg36. I add your code on admin.js and functions.php but it does not work. if you have time can you try it on you wordpress installation and tell me please. Thanks again for your help!
    – Samuel
    Nov 29, 2017 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.