WordPress.org

Forums

[resolved] Shortcode Query (2 posts)

  1. graemebryson5
    Member
    Posted 1 year ago #

    Hey,

    I'm currently using a shortcode I found to display the username of the current logged in user. Using the currentuserinfo section in the codex, I've attempted multiple variations to have it display the 'firstname' instead. I'm a total novice with php - is this even possible with the current code I have (below)?

    add_shortcode( 'current-username' , 'ss_get_current_username' );
    function ss_get_current_username(){
        $user = wp_get_current_user();
        return $user->display_name;
    }

    Any advice would be massively appreciated!

  2. graemebryson5
    Member
    Posted 1 year ago #

    Worked it out - here's the code for anyone who needs it in the future! Just use the current-username shortcode to use it.

    add_shortcode( 'current-username' , 'ss_get_current_username' );
    function ss_get_current_username(){
        $user = wp_get_current_user();
        return $user->user_firstname;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic