Last active
December 21, 2015 13:29
-
-
Save eljamez/6313265 to your computer and use it in GitHub Desktop.
Wordpress Function for Functions.php, Get The Current Username from Anywhere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get the current user name from anywhere | |
// paste into functions.php | |
if ( ! function_exists( 'get_user_name' ) ) { | |
function get_user_name() { | |
global $current_user; | |
get_currentuserinfo();//populates current user var/object | |
$current_visible_name = $current_user->user_firstname; | |
if($current_visible_name == '') { | |
$current_visible_name = $current_user->display_name; | |
}; | |
echo $current_visible_name; | |
} | |
} | |
add_action("get_current_user_name","get_user_name"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment