Halloween Sale 15% off Ends in See the plans
PHP

"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.

Don’t have WPIDE yet? Install it on your site

Code

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">×</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 add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.