Skip to main content

Shortcodes in a welcome banner

Has anyone found a way to add the users name in a welcome banner (the logged in one of course). I have a functioning snippet that creates a functioning shortcode (works on a WP page). But my banner body only shows the "Welcome [current_user]"

I guess if not workable, this would be a feature request. Perfect place to say hi to the user that logs in :)

Thomas Oates

This seems to work when testing.

add_filter('fluent_community/welcome_banner_for_logged_in', 'customwelcomebanner', 10, 1);
function customwelcomebanner($welcomebanner){
    if ( is_user_logged_in() ) {
        $current_user = wp_get_current_user();
        $first_name = $current_user->first_name; 

        if ( ! empty( $first_name ) ) {
            $welcomebanner['title'] = 'Hello, ' . esc_html( $first_name ) . '!';
        } else {
            // Fallback to display name if the first name is not set
            $welcomebanner['title'] = 'Hello, ' . esc_html( $current_user->display_name ) . '!';
        }
    } else {
        echo 'Hello!';
    }

    return $welcomebanner;
}

Using your existing current_user shortcode, you could probably do this as well.

add_filter('fluent_community/welcome_banner_for_logged_in', 'customwelcomebanner', 10, 1);
function customwelcomebanner($welcomebanner){
    $welcomebanner['title'] = do_shortcode($welcomebanner['title']);
    return $welcomebanner;
}

Jamie Robe

Thomas! WOW!!!!!!!! That works great. Better than a shortcode. Exactly what I wanted to get in terms of a personalized greeting. I used fluentsnippets and your first example. Thank you so much, Jamie