WordPress前台如何显示登录用户的最后登录时间

WordPress用户功能比较弱,很多国人熟习的一些用户信息都无默认的调用代码,比如用户注册时间、最后登录时间等,下面由WordPress教程栏目给大家分享一个前台显示用户最后登录时间的代码。

WordPress前台如何显示登录用户的最后登录时间

可以将下面的代码添加到当前主题functions.php中:

// 记录登录时间 function user_last_login($user_login) {     global $user_ID;     // 纠正8小时时差     date_default_timezone_set(PRC);     $user = get_user_by( 'login', $user_login );     update_user_meta($user->ID, 'last_login', date('Y-m-d H:i:s')); } add_action('wp_login','user_last_login'); // 调用最后登录时间 function get_last_login($user_id) {     $last_login = get_user_meta($user_id, 'last_login', true);     $date_format = get_option('date_format') . ' ' . get_option('time_format');     $the_last_login = mysql2date($date_format, $last_login, false);     echo $the_last_login; }

在主题模板适当位置添加调用代码:

<?php global $userdata; get_currentuserinfo(); get_last_login($userdata->ID); ?>

如果想在后台用户列表中显示最后登录时间可以安装插件:WP Last Login 。

以上就是WordPress前台如何显示登录用户的最后登录时间的详细内容,更多请关注七哩云社其它相关文章!

wordpress教程

如何显示WordPress登录用户角色

2022-6-13 21:31:41

wordpress教程

删除后台标题中的WordPress后缀的方法

2022-6-13 21:31:47

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
有新私信 私信列表
搜索