# Elementor Dynamic Tag: Visitor's First Name

> Adds a dynamic tag that shows the logged-in visitor's first name (or a fallback word like "there"), for greetings such as "Welcome back, Anna".

- Type: PHP
- Runs: Run everywhere
- Category: [Page Builders & Themes](https://wpide.com/library/category/page-builders/)
- Tags: elementor, dynamic-tags, users, personalization
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/elementor-dynamic-tag-visitor-name/

## Code

```php
add_action( 'elementor/dynamic_tags/register', function ( $dynamic_tags ) {
    if ( ! class_exists( '\Elementor\Core\DynamicTags\Tag' ) || ! class_exists( '\Elementor\Modules\DynamicTags\Module' ) ) {
        return;
    }

    if ( ! class_exists( 'WPIDE_Elementor_First_Name_Tag' ) ) {
        class WPIDE_Elementor_First_Name_Tag extends \Elementor\Core\DynamicTags\Tag {
            public function get_name() {
                return 'wpide-first-name';
            }

            public function get_title() {
                return 'Visitor First Name';
            }

            public function get_group() {
                return 'wpide-visitor';
            }

            public function get_categories() {
                return array( \Elementor\Modules\DynamicTags\Module::TEXT_CATEGORY );
            }

            protected function register_controls() {
                $this->add_control( 'fallback_name', array(
                    'label'   => 'Fallback for guests',
                    'type'    => \Elementor\Controls_Manager::TEXT,
                    'default' => 'there',
                ) );
            }

            public function render() {
                $user = wp_get_current_user();
                $name = $user->exists() ? ( $user->first_name ? $user->first_name : $user->display_name ) : $this->get_settings( 'fallback_name' );

                echo esc_html( $name );
            }
        }
    }

    $dynamic_tags->register_group( 'wpide-visitor', array( 'title' => 'Visitor' ) );
    $dynamic_tags->register( new WPIDE_Elementor_First_Name_Tag() );
} );
```

## Notes

Needs Elementor Pro. Pages using it 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 "Elementor Dynamic Tag: Visitor's First Name" 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/
