Site logo

Archived topic

hook the name of the user

3 replies · Started by Leonardo on March 2, 2023

Viewing posts 1–4 of 4

Is there a possibility that I can hook the name of the user that is logged in dynamic tags?

Situation: I'm creating a Hero Page and I want the name of the logged in user to always appear as the subtitle of the page.

Thanks!

Hi Leonardo,

You can use this PHP code to create a shortcode, so you can use this shortcode [current_user_name] on your hero page.

// Define the shortcode function
function current_user_name_shortcode() {
    $current_user = wp_get_current_user();
    $user_name = $current_user->display_name;
    return  $user_name;
}

// Register the shortcode
add_shortcode( 'current_user_name', 'current_user_name_shortcode' );

Adding PHP: https://docs.generatepress.com/article/adding-php/

Thanks!!!

No Problem :)

This archived topic is closed to new replies.