We manage multiple WordPress websites with dozens of users, so we know how important it is to track user activity. One of the most useful pieces of information is when users last logged in – it helps us spot inactive accounts and maintain better security.
But WordPress doesn’t show this information by default. That said, we’ve discovered and tested various ways to track user login dates. We’ve narrowed it down to two straightforward methods that work reliably without slowing down your site.
In this guide, we’ll teach you exactly how to show your users’ last login to WordPress. Whether you’re running a membership site, an online course platform, or managing multiple contributors, these methods will help you better monitor user activity and keep your site secure.

Why Display User’s Last Login Date in WordPress?
Adding a user’s last login column to your WordPress dashboard and front end helps keep track of when authors, admins, editors, contributors, and other users are logging in and out of your WordPress site.
This is extremely useful for securing your website from any suspicious activity and cyber threats.
For instance, let’s say your site is exposed to a vulnerability caused by a WordPress plugin installed by a user. You can use the last login date to track users and then quickly fix the problem.
Similarly, showing the user’s last login date makes it easier to monitor the time admins, contributors, authors, and others are spending working on your site. You can use this on a multi-author site and track the time spent by each user.
That said, there are 2 ways to show the user’s last login date in WordPress. First, you can use a plugin to show the login date inside the WordPress admin panel. Second, you can manually show the last login date using a custom code snippet.
Simply click the links below to jump ahead to your preferred section:
Method 1: Showing a User’s Last Login Date in WordPress Admin Area
You can easily show the last login date using the WP Last Login plugin. This method is easier, but it will only show a user’s last login date inside the WordPress admin area.
The first thing you need to do is install and activate the WP Last Login plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.
🚨 Note: Keep in mind that the WP Last Login plugin hasn’t been tested with that latest version of WordPress. However, when we tried it out on our test site, it seemed to be working fine. If you are still unsure, then check our beginner’s guide on the use of outdated plugins.
The best thing is that the plugin works out of the box, and there are no additional settings you have to worry about.
Upon activation, you need to visit the Users » All Users page in the admin area. You will notice a new column showing each user’s last login date.

At first, it may show ‘never’ for all users. That’s because a user needs to log in since the plugin has been activated so that it can capture the last login date and store it.
Method 2: Manually Show User’s Last Login Date in WordPress
This method allows you to display a user’s last login date anywhere on your WordPress site.
However, it requires adding custom code to your theme’s functions.php file or a site-specific plugin. We don’t recommend editing the functions.php file directly because the slightest mistake can break your website.
An easier way of adding custom code to your site is by using the WPCode plugin. It is the best code snippet plugin for WordPress that helps manage, organize, and insert custom code anywhere on your site without breaking anything.
Plus, we love its AI code generator that will create custom code for you. To learn more, see our detailed WPCode review.
First, you’ll need to install and activate the WPCode plugin. If you need help, then please see our guide on how to install a WordPress plugin.
Note: There is also a free WPCode plugin that you can use for this tutorial. However, upgrading to the premium plugin will give you access to a cloud-based code snippet library, smart conditional logic, and more.
Upon activation, you can go to Code Snippets » + Add Snippet from the WordPress dashboard.
Next, simply hover over the ‘Add Your Custom Code (New Snippet)’ option and click on ‘Use snippet’.

After that, you can copy the following code and add it into the Code Preview area:
<?php
/**
* Capture user login and add it as timestamp in user meta data
*
*/
function user_last_login( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', 'user_last_login', 10, 2 );
/**
* Display last login time
*
*/
function wpb_lastlogin() {
$last_login = get_the_author_meta('last_login');
$the_login_date = human_time_diff($last_login);
return $the_login_date;
}
/**
* Add Shortcode lastlogin
*
*/
add_shortcode('lastlogin','wpb_lastlogin');
?>
This code adds the last login as a meta key.
Each time a user logs in, it saves the time as a meta key value.
After entering the code, you will also need to enter a title for your custom code and select the ‘Code Type’ as PHP Snippet.

From here, you can scroll down and choose where to insert the code.
For this tutorial, we will use the default method and keep it to the ‘Auto Insert’ method. This way, the custom code will run everywhere on your website.

Once you are done, simply scroll back to the top.
Go ahead and activate your custom code snippet and click the ‘Save Snippet’ button.

If you are new to adding code, then please read this guide on pasting code from the web.
You can then display the last login date value using the[lastlogin]
shortcode in your WordPress posts and widgets.
Simply edit a post or page and go to the content editor.

From here, add a Shortcode block where you want to show the last login date and paste the shortcode.
Similarly, if you want to show the last login information in your child theme, then you can add this code instead:
<?php echo 'Last seen: '. do_shortcode('[lastlogin]') .' ago'; ?>
Before you test the plugin, you will need to log out of WordPress and then log in again.
Then, you should visit your WordPress website to see the login date in action.

As you will notice, this code displays the relative date and time, ‘2 hours ago’ instead of the full date and time.
If you want to display the full date and time, then you need to find this line in the code above:
$the_login_date = human_time_diff($last_login);
Now replace it with this line:
$the_login_date = date('M j, Y h:i a', $last_login);
The ‘M j, Y h:i a’ part in this code is called the date and time format string. If you want to change how this code displays the date and time, then just check out our guide on how to change the date and time format in WordPress.
We hope this article helped you learn how to show a user’s last login date in WordPress. You may also want to see our guide on how to add an author info box in WordPress posts and our tutorial on how to add social login to WordPress.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Christopher Garret
Thank you, very useful. I appreciate the code, which allows me to customize how to collect this data!
WPBeginner Support
Glad you found it helpful!
Admin
Louise Panvig
Hi is it possible to show a red dot if the user is offline and a green dot if they are online?
WPBeginner Support
That would be a different plugin, for something close to that, we would recommend taking a look at our article below:
https://www.wpbeginner.com/wp-tutorials/how-to-show-real-time-online-users-in-wordpress/
Admin
Babak Fakhamzadeh
It is worth being aware of that Wordfence stores the last login date as a meta field.
WPBeginner Support
Thanks for sharing that current feature for those using Wordfence.
Admin
Fredrick Arije
Thanks for the script.
I have an observation. All users sees the last login of the admin (author).
Is there a way for each user to see their own last login?
Please help. Thanks
WPBeginner Support
For showing individual last logins we would recommend using the plugin method as a manual code method would be more advanced than what we would recommend for beginners.
Admin
Bobby
Hello,
It works great but the time stamp when the line is changed for date/time still shows a 7 hour time difference?
How can I make the last login time show Pacific Standard Time. That is my timezone.
Please advise, thanks.
Cheers!
Nobin
Thanks For Share
That was most useful trick