Objective: This checklist walks you through the steps to take to retrieve user information from your WordPress site and display it in a post, Page or sidebar.
Displaying in the sidebar
- Using a text editor or via your WordPress admin > Appearance > Editor, locate and open the sidebar.php file in your current template folder.
- Scroll to the location you want to place the user’s name and paste the following PHP code. You can also paste this code into a widget, but you must have a plugin such as Executable PHP Widget plugin installed.
<?php global $current_user; get_currentuserinfo(); ?> Hello <?php echo $current_user->user_firstname; ?> <?php echo $current_user->user_lastname; ?>
- You may have to adjust the HTML around the PHP code so the name will display properly, depending on your theme.
- Save the sidebar.php file
- Refresh your page. You must be logged in to be able to view the changes.
Displaying in a Page or post
- Install or make sure a plugin that lets you run PHP such as PHP Execution is installed.
- Create a new post or Page
- Paste the code from step 2 above
- Click Save Draft or Publish