WordPress前台显示登录用户的注册时间

2020年01月9日17:55:09 发表评论 热度386 ℃

WordPress前台显示登录用户的注册时间

正常WordPress前台和后台都不会显示用户的注册时间,有时需要在前台显示登录用户的注册时间,可以用下面的代码实现。

将代码添加到当前主题functions.php中:

  1. function user_registered_date(){
  2.     $userinfo=get_userdata(get_current_user_id());
  3.     $authorID$userinfo->id;
  4.     $user = get_userdata( $authorID );
  5.     $registered = $user->user_registered;
  6.     echo '注册时间' . date( 'Y年m月d日', strtotime$registered ) );
  7. }

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

  1. <?php if ( is_user_logged_in() ) { user_registered_date();} ?>

只有登录用户可见。

瓜皮猪

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: