Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More →Display user last login time in WordPress by hooking into wp_login action and storing timestamps with user meta. Show login history to users for transparency, security awareness, and account monitoring with formatted date display.
You can display a user's last login time in WordPress by hooking into the login process and saving the login timestamp. Here's how to set this up: Step 1: Open your theme’s functions.php file. Step 2: Add the following code snippet:
// Record last login time
function update_last_login($user_login) {
$user = get_user_by('login', $user_login);
$current_time = current_time('mysql');
update_user_meta($user->ID, 'last_login', $current_time);
}
add_action('wp_login', 'update_last_login', 10, 2);
// Display last login time
function display_last_login() {
if (is_user_logged_in()) {
$user = wp_get_current_user();
$last_login = get_user_meta($user->ID, 'last_login', true);
if ($last_login) {
$formatted_date = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($last_login));
echo 'Last login: ' . $formatted_date;
}
}
}
Step 3: Save the file and upload it. Step 4: Use this line where you want the login time displayed:
<?php display_last_login(); ?>
wp_loginget_user_by(), update_user_meta()date_i18n()last_login) 
Search our archives or reach out to our team for solutions and expert advice.
150+ मुफ्त डेवलपर और SEO टूल्स
JSON, CSS/JS Minifier, SEO Analyzer & more — DotIAM Tools par
JSON, CSS/JS मिनिफायर, SEO एनालाइज़र और भी बहुत कुछ — DotIAM Tools पर
Our other free platforms you'll love
1000+ Hindu, Muslim & Modern baby names with meaning in Hindi & English
20+ AI-powered tools, 200+ Expert plant care guides and many more
150+ free online tools — AI, Astrology, Calculator, Kids Learning aur bahut kuch
Daily aarti, chalisa aur sandhya prayers — free devotional content