I used following code

function userinfo_global() {
    global $users_info;
    wp_get_current_user();
}
add_action( 'init', 'userinfo_global' );

in a file users.php , this file are call in inside funtions.php.

in template file I have <?php echo $users_info->user_firstname; ?> , but no working..

I want to do global wp_get_current_user();

You know why?

2 Answers
2

You’ll also have to fill the variable, e.g.

function userinfo_global() {
    global $users_info;
    $users_info = wp_get_current_user();
}
add_action( 'init', 'userinfo_global' );

And you should then be able to use $users_info everywhere in global context. Keep in mind that some template pars (header.php, footer.php, those used via get_template_part) are not in global scope by default, so you’ll have to use global $users_info; in those files before accessing the variable.

Leave a Reply

Your email address will not be published. Required fields are marked *