How change wordpress password without logout ( need for plugin )

If you are changing the password for the current logged-in user, it will log you out. You have to log in again:

// Get current logged-in user.
$user = wp_get_current_user();

// Change password.
wp_set_password($new_password, $user->ID);

// Log-in again.
wp_set_auth_cookie($user->ID);
wp_set_current_user($user->ID);
do_action('wp_login', $user->user_login, $user);

Note that since you are setting a new log-in cookie (i.e. changing headers), you need to run this code before any other output (HTML or echos).

Leave a Comment