Site logo

[Resolved] hook the name of the user

Home Forums Support [Resolved] hook the name of the user

Home Forums Support hook the name of the user

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2553385
    Leonardo

    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!

    #2553500
    Ying
    Staff
    Customer Support

    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/

    #2554464
    Leonardo

    Thanks!!!

    #2554597
    Ying
    Staff
    Customer Support

    No Problem 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.