2

I have a form that is on the front end of my site. I'm trying to remove the "Remember me" checkbox but can't get this to work. Here is my form code.

<?php

    $args = array(
        'echo'           => true,
        'remember'       => true,
        'redirect'       => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
        'form_id'        => 'loginform',
        'id_username'    => 'user_login',
        'id_password'    => 'user_pass',
        'id_remember'    => 'rememberme',
        'id_submit'      => 'wp-submit',
        'label_username' => __( 'Username' ),
        'label_password' => __( 'Password' ),
        'label_remember' => __( 'Remember Me' ),
        'label_log_in'   => __( 'Log In' ),
        'value_username' => '',
        'value_remember' => false
    );


    wp_login_form( $args );
    ?>

I have tried this code, but I think this would be for the wp-admin form (and it doesn't work on my form.

add_action('login_head', 'do_not_remember_me');
function do_not_remember_me()
{
echo '<style type="text/css">.forgetmenot { display:none; }</style>';
}

Any ideas on how to do this properly?

2 Answers 2

2

There is a remember argument for wp_login_form(). Just set it to false:

$args = array(
    'remember' => false,
);

wp_login_form( $args );
0

Look at your generated page code (or use the Inspect Element) to see what CSS class is assigned to the area you want to block. Then add that CSS code to your Additional CSS in your theme.

If the CSS class is 'rememberme', then

.rememberme {display:none !important;}

in the Additional CSS of your theme (via the Customizer) should work to hide that block.

Added

You might look into the login_form_defaults filter, as in

add_filter('login_form_defaults', $args);

Using your $args. This is supposed to set the default arguments for the wp_login_form() function.

...and the class used by wp_login_form is login-remember about line 470 in the https://core.trac.wordpress.org/browser/tags/4.9.6/src/wp-includes/general-template.php#L0 core code. (Looking at the core code is always helpful...)

** Added **

Well, the above code is not correct. According to the docs, this should work:

    add_filter( 'login_form_defaults', 'wp_disable_remember_me',10,1);

function wp_disable_remember_me($args ) {

    $args['value_remember'] = false;
    $args['remember']= false;
return $args;
}

....but it doesn't. Not sure why; have tested it with several sites/themes.

So perhaps the CSS 'hide' solution is the only choice.

2
  • Wouldn't that just be a CSS patch though? Is there no way to remove html from the form? Commented Jun 19, 2018 at 19:23
  • The CSS patch is how he was doing it, and it didn't work. It's not apparent if he is doing the wp-admin login, or his own on a page (although I suspect on a page). That's why looking at his generated page source will give him a hint on where to look. There might be a 'hook' in the wp_login() function, but the $args he is specifying (remember=false) should work - but perhaps only for the wp-admin login? Commented Jun 19, 2018 at 19:26

Your Answer

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

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