# "Referred By" Welcome Banner (AffiliateWP)

> Greets visitors who arrive through an affiliate link with a small banner naming the person who referred them, which builds trust and lifts conversions.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: affiliatewp, referrals, banner
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/affwp-referred-by-banner/

## Code

```php
$wpide_text = 'Welcome! You were referred by %s.'; // %s = affiliate first name.

add_action( 'wp_footer', function () use ( $wpide_text ) {
    if ( ! function_exists( 'affiliate_wp' ) || is_admin() ) {
        return;
    }

    $affiliate_id = absint( affiliate_wp()->tracking->get_affiliate_id() );

    if ( ! $affiliate_id || ! affwp_is_active_affiliate( $affiliate_id ) ) {
        return;
    }

    $affiliate = affwp_get_affiliate( $affiliate_id );
    $user      = $affiliate ? get_userdata( $affiliate->user_id ) : false;
    $name      = $user ? ( $user->first_name ? $user->first_name : $user->display_name ) : '';

    if ( ! $name ) {
        return;
    }
    ?>
<div class="wpide-referred-by" role="status" style="position:fixed;inset-inline:16px;bottom:16px;max-width:420px;margin-inline:auto;padding:12px 40px 12px 16px;background:#1d2327;color:#fff;border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.2);z-index:9999;font-size:14px">
    <?php echo esc_html( sprintf( $wpide_text, $name ) ); ?>
    <button type="button" aria-label="<?php esc_attr_e( 'Close' ); ?>" onclick="this.parentNode.remove();try{sessionStorage.setItem('wpideRefBanner','1')}catch(e){}" style="position:absolute;top:6px;inset-inline-end:8px;background:none;border:0;color:inherit;font-size:20px;cursor:pointer">&times;</button>
</div>
<script>try{if(sessionStorage.getItem('wpideRefBanner')){document.querySelector('.wpide-referred-by').remove();}}catch(e){}</script>
    <?php
} );
```

## Notes

Shows the affiliate's first name only. Change $wpide_text; %s is replaced with the name.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Referred By" Welcome Banner (AffiliateWP)" 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/
