Your header.php file is going to be called after the init action. If you want the logic to run in your header.php file first, maybe you can hook into another action done at a later point in WordPress:
add_action('wp_head', 'ax_get_user_info');
function avox_get_user_info() {
if (is_user_logged_in()) {
$currentUser = wp_get_current_user();
$fName = $currentUser->user_firstname;
}
return $fName;
}
init is done very early on, while wp_head is called in your header.php file most likely after your other logic is being fired. You can see here init is called before get_header, which is calling your header.php file.
https://codex.wordpress.org/Plugin_API/Action_Reference
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head
Hope that helps!!
Related Posts:
- How to remove the Theme Customization Button from the dashboard and themes options page?
- Display a different theme for not logged-in users
- Get password when user registers and save it sha1 into database
- Passing variable in hooks and filter
- Highlight “Show all” item in wp_list_categories
- Menu item added in wp_nav_menu_items filter is never highlighted
- Pass variable to hook. Its possible?
- How to change footer credit text in Twenty Twenty One theme with a hook?
- Modify available templates (in dropdown)
- what is do_action(); in wordpress? [duplicate]
- Is there any filter or action hook to remove layout classes from appearing in my templates?
- get_template_part vs action hooks in themes
- Theme Activate Hook
- Issues with title-tag and document_title_parts
- Add custom classes to anchor in wp_nav_menu
- What filters are applied to the_content function?
- Change admin bar to default:off
- How to modify an image block in Gutenberg WordPress 5?
- Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
- Getting instance variable in scope of ‘wp_enqueue_scripts’
- wp_get_attachment_image_attributes not working for me
- How do I Make a Theme “plugin-ready”?
- What can I hook into after_setup_theme?
- Run shortcode before filters
- Add class to before_widget for all widgets with a dropdown and a counter
- How to Auto Approve Comments on a Specific Page?
- Identifying the priority of style.css so I can make a small CSS file load last
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- wp_enqueue_scripts not called on search page?
- WordPress nav_menu_css_class theme filter is not being called
- customizing the_password_form filter
- WordPress Genesis Child Theme Filter divs
- Change file name from wp_generate_attachment_metadata
- Creating multiple hooks for theme
- How to add theme support?
- Simple way to get two language WP site
- Should I use function_exists() and/or add_action() in theme development?
- When trying to override plugin’s function by theme, my filter executes two times, I want it to run only a single time
- Injecting a custom sql query into a page/theme
- Single-level menu option? Another way?
- Should I use add_filter for functions in function.php of the theme?
- How to change database values on theme update
- What is the “correct” way to add hooks or similar PHP behavior to a blocktheme?
- Show notice just below the search form on the themes page
- Default image size not working
- Theme Development: Starter Content after hook
- WordPress taxonomy and archive custom class
- WordPress custom taxonomy check box to dropdown
- Filter categories used with Custom Structure Permalink
- Theme Customizer not loading JS for live preview
- Dynamic menu links after header title
- How to wrap all titles generated by Gutenberg “Heading” block with tag
- What are the hooks in WordPress theme development?
- Replace single_template filter with what for default posts?
- Unique design inside a specific category’s url
- How to rotate every letter in a title
- How to disable thumbnail filter for a specific template part or image size?
- CSS class on last post in loop ( custom query )
- Use a filter on menu items that have children
- Difference between “comment_form_default_fields” AND “comment_form_fields”
- Is There A WordPress Hook for Accessing Attachments for A Particular Page?
- tiny_mce_before_init: ‘exact’ => true has no effect
- pre_get_comments or the_content filter
- How to conditionally add a wp_filter
- Add content after get_header
- Filter didn’t work on content class (hybrid_post_attributes)
- How to set default values for edit_post_link() in my theme?
- Tiny MCE custom styles, and preview in the backend
- content filter (add_filter) for category description?
- Related Post Category Filter
- Pagination don’t work with active filters
- How to register dynamic settings in WordPress Customizer?
- restrain filter on get_the_excerpt to queried item in stead of current post
- Unpublished Pages Failing To Appear On Custom Path
- Put CSS Content inside tag for WordPress
- Alternative solution for script_loader_tag?
- Alt header logo and link for specific pages
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- How to hook into wordpress upgrade procedure for a custom theme
- Alter theme pages on language switch
- Make a custom field in admin post.php read only
- Hook in parent theme Menu function
- How do I remove p tag *insertions*? Disabling `wpautop` removes manual tags
- How to add custom nav_menu_css_class to certain menu only?
- How to manipulate wordpress template tags’ output
- Suppress the_content filter in a nested loop
- apply_filters to featured image
- Add rel to all images in a post
- Add text when displying attribute with a hook on single product page
- Custom Theme: The active theme is broken. Reverting to the default theme
- Customize comment list markup
- Can a child theme based on Starker theme be released as free to use theme for public use?
- Do i need to keep all the default WP templates files in a theme?
- How to show user online status on their posts?
- How to display all subpages and short by year
- Is this hook really deprecated? ( manage_{$taxonomy}_custom_column )
- Changing sidebar.php and footer.php depending on URL
- ACF get_sub_field ALT TAG in the repeater doesn’t show