I'm building a site where users log in to view content specific to them. I would like to display the last date and time they logged in. How would I get this information from wordpress? If it doesn't exist, how could I add it?

Example: Welcome Back! Your last visit was on 10/25/2010 at 3:14pm.


1 Answer 1


I don't see anything like it in the database, so you probably have to do this yourself. To save the last login time, you can hook into the wp_login action, and save a user meta value (like [myprefix]_lastlogintime). You first read this value, so you get the previous login time, save this in the session, and then save the new login time.

On the regular admin pages you check whether this session variable is set. If it is, you display the welcome text and clear the session variable so you don't display it on every page.

If you want to save the last page visit time you have to write to the database on every (admin) page view. This is possible, but I would not recommend it. You can also save something once on logout (action wp_logout), but probably not everyone will remember to log out.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.