# "Welcome Back" Message After Logging In

> Shows a small, dismissible "Welcome back, Sam!" notice on the front of the site right after a member logs in.

- Type: PHP
- Runs: Run everywhere
- Category: [Login](https://wpide.com/library/category/login/)
- Tags: login, members, notice
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/welcome-back-message-after-login/

## Code

```php
add_action( 'wp_login', function ( $login, $user ) {
    update_user_meta( $user->ID, 'wpide_welcome_back', 1 );
}, 10, 2 );

add_action( 'wp_footer', function () {
    $user_id = get_current_user_id();

    if ( ! $user_id || ! get_user_meta( $user_id, 'wpide_welcome_back', true ) ) {
        return;
    }

    delete_user_meta( $user_id, 'wpide_welcome_back' );
    $user = wp_get_current_user();
    $name = $user->first_name ? $user->first_name : $user->display_name;
    ?>
    <div id="wpide-welcome" role="status" style="position:fixed;left:16px;right:16px;bottom:16px;max-width:360px;margin-left:auto;padding:12px 44px 12px 16px;border-radius:8px;background:#1d2327;color:#fff;box-shadow:0 4px 16px rgba(0,0,0,.25);z-index:99999">
        <?php echo esc_html( sprintf( 'Welcome back, %s!', $name ) ); ?>
        <button type="button" aria-label="Dismiss" onclick="this.parentNode.remove()" style="position:absolute;top:6px;right:8px;background:none;border:0;color:inherit;font-size:20px;cursor:pointer">&times;</button>
    </div>
    <script>
    setTimeout(function () {
        var el = document.getElementById('wpide-welcome');
        if (!el) { return; }
        if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) { el.remove(); return; }
        el.style.transition = 'opacity .4s';
        el.style.opacity = '0';
        setTimeout(function () { el.remove(); }, 400);
    }, 6000);
    </script>
    <?php
} );
```

## Notes

The notice shows once per login and disappears after 6 seconds; it respects reduced-motion settings.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Welcome Back" Message After Logging In" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
