I have a "change password" page.

Is there a way to redirect that page when the user login first time using wordpress generated password?


3 Answers 3


Maybe this helps you?


He seems to had a similar problem and solved it a year ago.

What he does different to your approach is redirecting 48hrs after registration. Maybe this is enough?

If not - I'm looking to do it your way.

--- EDIT

Okay I just made a plugin what does exactly what you want:

 Plugin Name: Redirect Passwort
Plugin URI: TODO
Description: TODO
Author: xaeDes
Version: 0.1
Author URI: TODO
License: GPL2

function redirect_passwort_profile_update($user_id, $old_user_data) {
    $user = new WP_User( $user_id );
    if( $user->data->user_pass != $old_user_data->user_pass) {
        //password has changed
add_action("profile_update", "redirect_passwort_profile_update", 10, 2);

function redirect_passwort_login_redirect($redirect_to, $url_redirect_to = '', $user = null) {

    if( isset($user->ID) ) {
        $changed_password = get_metadata("user", $user->ID, "changed_password",true);
        if( $changed_password != true ) {
            return get_bloginfo('url') . "/change-your-password-dude/";
        } else {
            return $redirect_to;
add_filter('login_redirect', 'redirect_passwort_login_redirect',10,3);

function redirect_passwort_password_reset( $user ) {
    //password has been reset to a random one. so the changed_password meta data should be reset as well
    if( isset($user->ID) ) {
        delete_metadata("user", $user->ID, "changed_password");
add_action('password_reset', 'redirect_passwort_password_reset');

It adds a user meta data "changed_password" to the user who changed its passwort.

When logging in it checks whether the user meta data "changed_password" is set and redirects if it is not set (and therefore the user has not changed its passwort even once).

When the users password is reset to a random one, the user meta data "changed_password" is reset as well.

  • I don't think its a good idea redirecting users to "change password" page based on 48hours time. It will be problem if the user login defferent times in those 48 hours. I don't want to redirect that user to change password page often. Mar 25, 2012 at 16:05
  • Hi Thanks for the code. I tested your code. But its not working in my site. I'm using custom page for login. Is that the reason why its not working? Here is my login function. Do i have to modify any codes there? Thanks Mar 25, 2012 at 17:46
  • You have to change the url of the site you are redirecting to in my plugin: return get_bloginfo('url') . "/change-your-password-dude/"; You are using wp_redirect to redirect to a site. But my plugin hooks into login_redirect, which is called from standard wordpress login. You could apply the login_redirect for yourself : wp_redirect(apply_filters('login_redirect', get_bloginfo('url') . '/my-account/','', $user);); in your pastebin line 19. Does that solve your problems?
    – xaedes
    Mar 25, 2012 at 17:58
  • No it doesn't. Here is my modified login function. I created a new user and tested it. Its supposed to redirect to change-password page. But it still redirect to my-account page. And yes i replaced your change-your-password-dude text with my change-password text. Any idea whats wrong? Mar 25, 2012 at 18:16
  • Which wordpress version are you using? Could you check whether redirect_passwort_profile_update or redirect_passwort_login_redirect are ever called? Maybe add something like this as first line of the files : file_put_contents(dirname(__FILE__).'/log-'.__FUNCTION__.'_'.__LINE__, ''); and check the folder of the plugin for generated files. The folder of the plugin have to be writable for the webserver.
    – xaedes
    Mar 25, 2012 at 18:28

Hook user_register and add user metadata to store a "has not logged in yet" flag. Hook wp_login and check for that metadata, delete and redirect if it exists, otherwise do normal login behavior.


In addition to Milo's answer:

    function after_user_register( $user_id ){

        // the new user just registered but never logged in yet
        add_user_meta($user_id, "has_not_logged_in_yet", "true", true);

    add_action( 'user_register', 'after_user_register', 10, 1 );

    function after_user_loggedin(){





                delete_user_meta($user_id, "has_not_logged_in_yet");

                //do something else

    add_action( 'init', 'after_user_loggedin');

Edit (FYI)

Hook wp_login is not performing very well in terms of user meta retrieval. Sometimes returns FALSE with the user loggedin.

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.