How to Show a User’s Last Login Date in WordPress (With and Without a Plugin)

WordPress doesn’t record when a user last logged in. To see it, you need something that saves a timestamp on the wp_login hook (the free When Last Login plugin or a short snippet) and shows it as a Last Login column under Users > All Users. Neither one can fill in logins from before you installed it.

That’s useful for spotting dormant accounts, and dormant admin accounts with old passwords are an easy target. One catch most guides skip: wp_login only fires when someone types a password into a login form. Returning “remember me” visitors, Application Password requests, and XML-RPC clients never trigger it, so “last login” and “last active” can be days or weeks apart. I cover both below.

Quick reference: every way to check last login

MethodWhat it recordsCatches remember-me and REST activity?Setup
When Last Login pluginLast login time, login count, optional IPNo (uses wp_login)Install and activate
Code snippet (Method 2)Last login time in last_login user metaNo (uses wp_login)Paste into a snippets plugin
“Last seen” snippetLast request by a logged-in userYesPaste into a snippets plugin
WP Activity Log pluginFull history: logins, logouts, failed attempts, content changesNot tested hereInstall and activate
wp user session list (WP-CLI)Login time of each active sessionShows sessions still open, built inNothing to install
Application Passwords tableLast Used date and Last IP per app passwordYes, for app passwords onlyBuilt in (Users > Profile)
The two built-in options only cover sessions and passwords that still exist.

Method 1: Show Last Login with a Plugin

The easiest way to display a WordPress user’s last login time is the When Last Login plugin. It’s free, has 40,000+ active installs, and there’s nothing to configure.

After installing and activating the plugin, a sortable “Last Login” column shows up on Users > All Users.

When Last Login plugin showing last login dates in the WordPress user list
User’s last login in the WordPress user list

A few things it does beyond the column:

  • Counts logins per user and shows the top 3 in an admin dashboard widget.
  • Keeps a login history table under When Last Login > All Login Records (you can turn this off in its settings).
  • Optionally records each user’s IP address, with an anonymization option for GDPR.
  • Has a Tools section in its settings to clear old login records, all records, or stored IPs.

Users who haven’t logged in since activation show “Never.” The plugin stores the timestamp in the when_last_login user meta key, which matters if you want to query it later with WP-CLI or SQL (swap it in for last_login in the commands below).

Method 2: Show Last Login with a Code Snippet

If you’d rather not add a plugin, this snippet does the same job. Add it with the Code Snippets plugin or your child theme’s functions.php.

It does four things:

  • Saves the time of each successful login as last_login user meta.
  • Adds a “Last Login” column to the Users screen showing “2 hours ago” style text, with the full date on hover.
  • Makes that column sortable.
  • Registers a [lastlogin] shortcode for author boxes or member profiles. Use [lastlogin user_id=2] to show a specific user.
// 1. Save the time of every successful login.
add_action( 'wp_login', 'smartwp_capture_login_time', 10, 2 );
function smartwp_capture_login_time( $user_login, $user ) {
	update_user_meta( $user->ID, 'last_login', time() );
}

// 2. Add a Last Login column to Users > All Users.
add_filter( 'manage_users_columns', 'smartwp_user_last_login_column' );
function smartwp_user_last_login_column( $columns ) {
	$columns['last_login'] = 'Last Login';
	return $columns;
}

add_filter( 'manage_users_custom_column', 'smartwp_last_login_column', 10, 3 );
function smartwp_last_login_column( $output, $column_id, $user_id ) {
	if ( 'last_login' !== $column_id ) {
		return $output;
	}
	$last_login = (int) get_user_meta( $user_id, 'last_login', true );
	if ( ! $last_login ) {
		return 'No record';
	}
	$full_date = wp_date( 'F j, Y, g:i a', $last_login );
	return '<span title="' . esc_attr( $full_date ) . '">' . esc_html( human_time_diff( $last_login ) . ' ago' ) . '</span>';
}

// 3. Make the column sortable. Users with no record stay in the list.
add_filter( 'manage_users_sortable_columns', 'smartwp_sortable_last_login_column' );
function smartwp_sortable_last_login_column( $columns ) {
	$columns['last_login'] = 'last_login';
	return $columns;
}

add_action( 'pre_get_users', 'smartwp_sort_last_login_column' );
function smartwp_sort_last_login_column( $query ) {
	if ( ! is_admin() || 'last_login' !== $query->get( 'orderby' ) ) {
		return;
	}
	$query->set( 'meta_query', array(
		'relation'  => 'OR',
		'has_login' => array( 'key' => 'last_login', 'type' => 'NUMERIC' ),
		'no_login'  => array( 'key' => 'last_login', 'compare' => 'NOT EXISTS' ),
	) );
	$query->set( 'orderby', 'has_login' );
}

// 4. [lastlogin] shortcode. Defaults to the current post author.
add_shortcode( 'lastlogin', 'smartwp_lastlogin_shortcode' );
function smartwp_lastlogin_shortcode( $atts ) {
	$atts       = shortcode_atts( array( 'user_id' => get_the_author_meta( 'ID' ) ), $atts, 'lastlogin' );
	$last_login = (int) get_user_meta( (int) $atts['user_id'], 'last_login', true );
	return $last_login ? esc_html( human_time_diff( $last_login ) ) : '';
}

If you used the older version of this snippet from this post, two things changed. Sorting by the column used to drop every user with no record from the list entirely (in a WordPress Playground test, 2 of 4 users vanished). The meta_query with a NOT EXISTS clause keeps them in. The hover date now uses wp_date(), so it follows your site’s timezone setting instead of the server’s.

Last Login column added to WordPress user list via custom code snippet

Users who haven’t logged in since you added the code show “No record.” Hover over the relative time to see the full timestamp.

Hovering over last login time to see the full timestamp in WordPress

The 10, 2 on the first add_action() line matters: wp_login passes the username and the user object, and the callback needs the second one. Our guide to WordPress hooks explains how that accepted-arguments number works.

Why some users show no record (remember me, REST, and XML-RPC)

Both methods above hook wp_login, which core fires at the end of wp_signon(). Anything that authenticates without going through wp_signon() never updates the timestamp. Here’s what happened with each login path in WordPress Playground (WordPress 7.1, PHP 8.3):

How the user got inFires wp_login?Notes
Login form at wp-login.phpYesThe normal case
Custom form calling wp_signon()YesSame code path as wp-login.php
Returning visit with a “Remember Me” cookieNoCookie lasts 14 days (2 days without Remember Me), no new login happens
Auto-login via wp_set_auth_cookie()NoUsed by some auto-login and magic-link plugins
REST API with an Application PasswordNoFires application_password_did_authenticate instead
XML-RPC with username and passwordNoAuthenticates on every request
Tested in WordPress Playground: only the first two paths updated last_login.

So an editor who ticks Remember Me and keeps their browser open can work every day for two weeks and still show a last login from 14 days ago. An integration that posts through the WordPress REST API with an Application Password can show “No record” forever.

Track “last seen” instead

If what you really want to know is whether an account is still in use, record activity rather than logins. This snippet saves a last_seen timestamp on any request from a logged-in user, plus Application Password requests, and only writes to the database once every 15 minutes per user:

// Track "last seen": logged-in browsing plus Application Password requests.
add_action( 'init', 'smartwp_track_last_seen' );
function smartwp_track_last_seen() {
	smartwp_touch_last_seen( get_current_user_id() );
}

add_action( 'application_password_did_authenticate', 'smartwp_app_password_last_seen' );
function smartwp_app_password_last_seen( $user ) {
	smartwp_touch_last_seen( $user->ID );
}

function smartwp_touch_last_seen( $user_id ) {
	if ( ! $user_id ) {
		return;
	}
	$last_seen = (int) get_user_meta( $user_id, 'last_seen', true );
	if ( time() - $last_seen > 15 * MINUTE_IN_SECONDS ) {
		update_user_meta( $user_id, 'last_seen', time() );
	}
}

In testing, a REST request authenticated with an Application Password set last_seen while last_login stayed empty. To show it in the Users list, copy the column functions from Method 2 and swap last_login for last_seen.

Application Passwords also keep their own record. Open a user’s profile and the Application Passwords table has Last Used and Last IP columns. Core only updates those once a day, so treat them as a date, not a time.

Look up last login with WP-CLI or SQL

If you have shell access, you don’t need the Users screen at all. Get one user’s saved timestamp (a Unix timestamp):

wp user meta get admin last_login

WordPress also stores a login time for every session that is still open, even without any tracking code. That’s the closest thing to retroactive data you’ll get: it covers anyone who logged in within the last 14 days and hasn’t logged out.

wp user session list admin --fields=login_time,expiration_time,ip

Sessions live in the session_tokens user meta key and are deleted when they expire, so this won’t show anything older. To list every user with their last login in MySQL (change the wp_ prefix if yours differs):

wp db query "SELECT u.user_login, FROM_UNIXTIME(m.meta_value) AS last_login
FROM wp_users u
LEFT JOIN wp_usermeta m ON m.user_id = u.ID AND m.meta_key = 'last_login'
ORDER BY m.meta_value + 0 DESC"

Users with no record come back as NULL at the bottom. In PHP, this WP_User_Query finds accounts with no login in 90 days, including ones that were never recorded:

$inactive = new WP_User_Query( array(
	'meta_query' => array(
		'relation' => 'OR',
		array( 'key' => 'last_login', 'compare' => 'NOT EXISTS' ),
		array(
			'key'     => 'last_login',
			'value'   => time() - 90 * DAY_IN_SECONDS,
			'compare' => '<',
			'type'    => 'NUMERIC',
		),
	),
) );

Before you delete anyone that query returns, check the remember-me and REST gap above, and reassign their posts. If you need a user’s numeric ID for any of these commands, here are all the ways to get a WordPress user ID.

Which Method Should You Use?

Use the plugin if you want it working in two minutes with no code. Use the snippet if you want one less plugin, the frontend shortcode, or control over the output. Add the “last seen” snippet if any of your users stay logged in for days or connect apps through the REST API. All three store a single timestamp per user in wp_usermeta.

If you need a full login history (every login, logout and failed attempt), use an activity log plugin like WP Activity Log instead. Pruning dormant accounts is one piece of WordPress login security; rate limiting and two-factor authentication do far more.

Frequently Asked Questions

Does WordPress track last login by default?

No. Core doesn’t save a last login date anywhere you can see in the dashboard. The built-in traces are the login time stored with each active session (read it with wp user session list, gone once the session expires) and the Last Used date on each Application Password.

Can I see login dates for users who logged in before I added tracking?

Mostly no. The plugin and the snippet only record logins that happen after you add them. The exception is users with a session that’s still open: wp user session list username shows when that session started, which covers roughly the last 14 days.

Why does an active user show “Never” or “No record”?

They haven’t gone through a login form since you added tracking. Remember Me cookies keep people logged in for 14 days without a new login, and Application Password and XML-RPC requests skip wp_login entirely. Use the “last seen” snippet above to catch them.

Can I sort users by last login date?

Yes. Both the plugin and the snippet make the “Last Login” column sortable on Users > All Users. Click the column header to toggle between newest and oldest. If you’re cleaning up accounts while you’re there, you might also want to change a username.

How do I find inactive users in WordPress?

Track last login (or last seen) for a while, then sort the Users list by that column or run the WP_User_Query or SQL query above. Give it at least a few weeks before acting, since users who never logged in during that window will show no record.

Does tracking last login slow down my site?

No. The login snippet writes one row to wp_usermeta per login. The “last seen” snippet reads one meta value per logged-in request and writes at most once every 15 minutes per user, and logged-out visitors are skipped.


For most sites, the When Last Login plugin or the Method 2 snippet is all you need. If accounts that are clearly in use keep showing old dates, that’s the remember-me and REST gap, and the “last seen” snippet fixes it.

Picture of Andy Feliciotti

Andy Feliciotti

Andy has been a full time WordPress developer for over 15 years. Through his years of experience has built 100s of sites and learned plenty of tricks along the way. Found this article helpful? Buy Me A Coffee

10 Responses

  1. Hi Andy,

    Thanks for sharing both the plugin based and plugin-free ways. I would go with the plugin-based method 🙂

    Cheers!

  2. Hey, I added the code and it works well, but is there a way to show each user (like current user) his last login date after he logs in to the site?
    thanks

    1. 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

  3. hi Andy

    thanks for sharing !

    any idea how to maje the whole thing working alsi when the user check the “remember me” option ? (there is no login form here, so the time is not saved)

    thanks again !

  4. Dear ALL Beloved Friends,

    I am using code snippets plugin
    Would you mind telling me where to add this code ? is it on a body ? or File editor or else?
    or different plugin ,feel free to suggest

    Thanks
    PIPE

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Tips Monthly
Get the latest from SmartWP to your inbox.