You can use wp_get_current_user()
instead of using the $current_user
global.
$my_current_user = wp_get_current_user();
if ( $my_current_user->display_name ) {
echo '<p>Welcome ' . $my_current_user->display_name . '</p>';
}
Note that I used $my_current_user
instead of $current_user
as a variable name, because you can run into trouble if you use the global variable’s name.
Related Posts:
- How to: inspect global variables in WordPress
- get_post() vs global $post or $GLOBAL[‘post’]
- How to deal with global information without creating a Singleton class
- Using global $post v/s $GLOBALS[‘post’]
- Accessing $post global on a custom post type archive page
- get_query_var vs global query variables?
- What is the global $wp object used for?
- Change global values from templates
- Will $current_user no longer be global?
- How to avoid repeatedly use the new statement to instantiate a class? [closed]
- Is $page a global variable in wordpress?
- How can i use a global variable in a .css file generated with php?
- Current page id returns the incorrect value
- Echo get_the_category() outside of loop (global?)
- How does WordPress make its functions globally available?
- WP user agent returns random variables
- How to get particular data from wp_list_comments outside the loop?
- How to save a viewer specific option
- What is the correct way to obtain access to the WP_oEmbed object?
- $GLOBALS[‘value1’] is not working
- Creating a (global)-mapping
- wp localize script makes variable global, how to solve that?
- using globals from wp_link_pages function
- How to set and use global variables? Or why not to use them at all
- Should we trust the post globals?
- What is a good alternative to using $content_width for image optimization?
- Passing variables from header.php to template and vice verca
- When to use global $post and other global variables?
- Where to get information about array fields in $_REQUEST?
- Global Objects and Public Methods
- What is the difference between using global $current_screen and get_current_screen()?
- Why declare $post globally?
- Create a global variable for use in all templates
- How to set global variable in functions.php
- Passing variables to templates (alternatives to globalizing variables)
- Retrieve the template directory URI via global or get_template_directory_uri() every time?
- using 1 form shortcode (si or cf7) for all multisite sites [closed]
- Filter the blog title displayed in the header
- Multisite Installation: how do I setup global search?
- Passing variables to template parts
- Should I global $wpdb outside of any of my plugin’s functions scope?
- How should I store global information such as a phone number so that it is editable through the CMS?
- WP 4.4.1 allow empty comments via add_action ‘pre_comment_on_post’
- Multisite Global Custom Posts
- Adding a section to admin menu for global settings
- WordPress Multisite – global categories
- Add classname comment template from functions.php
- Cannot update custom database table row
- What are the disadvantages of using global variable?
- Defining a global array in functions.php?
- Call global variable array() in woocommerce child/template
- Override global query results without hooks
- WordPress Loop and $post
- Getting List of all registered Dashboard Widgets
- Create a new query in function.php to filter blog posts
- Relative redirects for posts, categories, products and product categories
- global variables in templates
- Global $post shows null in some of my custom post types archive pages
- Declare Global Variable In OOP PHP
- How can I save custom meta to one global value?
- Does WP have a global of $id?
- What is the use of $content_width?
- Use global variables or function that returns said variables for site-wide private-ish WP settings?
- WordPress Image Slider Looping Title Not Working
- Declare global var from Template File and use it in Functions.php
- get_posts() and global variables
- Passing global variable from header.php to functions.php
- Where is this function’s callback getting its arguments from?
- keep a variable for all pages in memory from the url
- Translation issue with global variables
- How to get submenu of admin menu?
- Detecting current page from class method
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- Retrieve post in AJAX Callback
- ‘global’ not working in wordpress?
- SFTP define in wp-config.php
- The Global Styles missing
- cannot get global $menu value in form request
- global $product is empty string when passed into function
- Define global custom post
- Custom global variable not working in function
- Hide payment method based on user role AND minimum cart value
- Global $wp_admin_bar always returns null
- How do I get a reference to the HTML memory buffer while the page is being constructed?
- global categories – Share specific categories in wordpress multisite
- global $post inside plugin query messes up every new post page in wp-admin
- Declare global variable that can be used on other function
- Setting a cookie in functions.php and it gets deleted when working on an other function
- Popup panel is only displaying 1 entry ignoring all others
- Best way to access variables in template markup
- Settings in functions.php used by a plugin
- How to set global variable in functions.php
- Current URL path variable
- Save something to global var in add_filter
- key( $GLOBALS[‘wp_registered_sidebars’] ) is always showing the same value
- How do I access variables outside a function [closed]
- WordPress Multisite and site speed and scaleability
- $do_not_duplicate is not working in genesis theme
- Suppress errors when using global function
- Dequeue classic-themes.min.css