# Personal Greeting Shortcode

> Adds a [wpide_hello] shortcode that greets logged-in members by first name ("Hi, Sam") and visitors with a fallback you choose.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: members, shortcode, personalization
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/personal-greeting-shortcode/

## Code

```php
add_shortcode( 'wpide_hello', function ( $atts ) {
    $atts = shortcode_atts( array( 'greeting' => 'Hi', 'guest' => 'there' ), $atts, 'wpide_hello' );
    $name = $atts['guest'];

    if ( is_user_logged_in() ) {
        $user = wp_get_current_user();
        $name = $user->first_name ? $user->first_name : $user->display_name;
    }

    return esc_html( sprintf( '%s, %s', $atts['greeting'], $name ) );
} );
```

## Notes

Example: [wpide_hello greeting="Welcome back" guest="friend"]. Pages with personal greetings should not be served from a full-page cache to logged-in users.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Personal Greeting Shortcode" 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/
