Insert Modal on user first login

The problem is that wp_login comes at the end of the wp_signon() function. But that’s not the end of things for logging a user in. After that, they are redirected (so that the auth cookie that is set during logon can be read). As a result, the user is wisked away to a new page an your footer action is never fired. So as written it will never work (hope it makes sense why).

You can just use your existing logic with the in_admin_footer action. Your logic doesn’t really need to determine if the user is completing a login or not because once they do log in the first time, the meta is changed.

This should resolve it:

/**
 * Set User meta.
 */
function fyc_register_add_meta( $user_id ) {
    add_user_meta( $user_id, '_new_user', '1' );
}
add_action( 'user_register', 'fyc_register_add_meta' );


/**
 * Loads pop-up on first login.
 */
function shapeSpace_first_user_login($user_login, $user) {

    $new_user = get_user_meta( $user->ID, '_new_user', true );

    if ( $new_user ) {

    update_user_meta( $user->ID, '_new_user', '0' ); ?>

        <div class="welcome-modal">
            <header>
                <h1>Welcome!</h1>
            </header>
        </div>

    <?php }
}
add_action( 'in_admin_footer', 'fsc_display_modal_first_login' );