"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.
Opens WPIDE on
Code
$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">×</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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.