Skip to content

Instantly share code, notes, and snippets.

@eljamez
Last active December 21, 2015 13:29
Show Gist options
  • Save eljamez/6313265 to your computer and use it in GitHub Desktop.
Save eljamez/6313265 to your computer and use it in GitHub Desktop.
Wordpress Function for Functions.php, Get The Current Username from Anywhere
// 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