do_action( ‘wp_login’, string $user_login, WP_User $user )

Fires after the user has successfully logged in.


WP_User object of the logged-in user.

More Information

The wp_login action hook is triggered when a user logs in by the wp_signon() function. It is the very last action taken in the function, immediately following the wp_set_auth_cookie() call.

This hook provides access to two parameters: $user->user_login (string) and $user ( WP_User ). To pass them into your function you will need to add a priority (default is 10) and request 2 arguments from the add_action() call:

function your_function( $user_login, $user ) {
// your code
add_action('wp_login', 'your_function', 10, 2);


do_action( 'wp_login', $user->user_login, $user );



User Contributed Notes

  1. Skip to note 2 content

    Sending a welcome email to first time logged in users.

    // callback function
    function wpdocs_send_welcome_email( $user_login, WP_User $user ) {
        // do not send email if user has already logged in once
        if ( current_user_can( 'administrator' ) || get_user_meta( $user->ID, 'wpdocs_welcome_email_sent', TRUE ) ) {
        // send welcome email if logging in first time
        $message = str_replace(
            array( '%%firstname%%', '%%name%%', '%%sitename%%' ),
                get_bloginfo( 'name' ),
            get_option( 'welcome_message' )
        // send email to user
        if ( wp_mail( $user->data->user_email, 'Welcome subject', $message ) ) {
            // update or add user meta if email sent successfully
            update_user_meta( $user->ID, 'wpdocs_welcome_email_sent', 1 );
    // action hook
    add_action( 'wp_login', 'wpdocs_send_welcome_email', 10, 2 );

You must log in before being able to contribute a note or feedback.