I set global variables for some custom user data in my functions.php to use them in navigation inside header and footer.
if (is_user_logged_in()) {
# users wordpress id
global $user_id_wp;
$user_id_wp = get_current_user_id();
# users meta page id
global $user_id_meta;
$user_id_meta = userMeta(get_current_user_id());
# users uuid
global $user_id_uuid;
$user_id_uuid = get_field("user-uuid", $user_id_meta);
}
Those variables cannot be used inside header.php
and footer.php
where I need them. Cannot be used means var_dump($user_id_meta)
results in NULL
, while userMeta($user_id_wp)
shows the correct values inside header or footer.
I have tried to set the lines above as function with add_action( 'init', 'globalUserVar' );
but no positive results either. Please help me use my global user vars inside the header and footer. Thanks so much!
get_current_user_id()
(as well asuserMeta()
andget_field()
) in your header and footer templates?footer.php
,sidebar.php
or a template part, why not just calluserMeta(get_current_user_id())
or (by passing a specific user ID -userMeta( 123 )
) right in that template file? And same goes withget_field()
.