If you have a WordPress site with a lot of users it can be important to audit who is actually using the site. For example if you have a lot of admins you periodically may want to trim down users.
This is where having a WordPress user’s last login date can be helpful. In this post we’ll be enabling a user’s last login time and you’ll be able to sort it so you can see who hasn’t logged in for a while.
First we’re going to be achieving this with a free plugin:
Displaying a WordPress User’s Last Login Date with a Plugin
The easiest way to show a WordPress user’s last login time is to use the When Last Login plugin.
After installing and activating the plugin you’ll see a new column in the user list.
If a user hasn’t logged in since you’ve added the plugin you’ll see “Never”.
Manually Show User’s Last Login Date Code Snippet
If you’re familiar with adding code snippets to your site via functions.php or the code snippets plugin you can use this to add the user’s last login time.
This code snippet does a few things, first it records the time a user logs in and saves it in the ‘last_login’ user meta. It also adds a sortable ‘Last Login’ admin column to the user list in the admin dashboard. Lastly it allows you to display the user’s last login via a [lastlogin] shortcode. The shortcode also lets you show a specific user’s last login by using the user_id variable [lastlogin user_id=2].
After adding this code snippet user’s logins will be recorded and you’ll see a new last login column. If a user hasn’t logged in since adding it you’ll se a “No record” message.
If you need to know the exact login time you can also hover over the time for the full timestamp.
Best of all if you are familiar with PHP you can easily customize all aspects of this functionality.
This code snippet also added the ability to display a user’s last login on the frontend. For example in your site’s author box you can include the [lastlogin] shortcode for users to see when the author was last online.
I hope this quick guide was useful on showing you how to display a user’s last WordPress last login. If you have any questions let me know in the comments below.