要在WordPress前台显示用户注册时间,您可以使用以下步骤:
functions.php
文件中:function display_user_registration_date($user_id) {
$user = get_userdata($user_id);
$registration_date = $user>user_registered;
echo '注册时间:' . date('Ymd H:i:s', strtotime($registration_date));
}
add_action('show_user_profile', 'display_user_registration_date');
add_action('edit_user_profile', 'display_user_registration_date');
这段代码会在用户个人资料页面上添加一个显示注册时间的字段。
single.php
,author.php
或profile.php
)中添加以下代码来获取和显示注册时间:<?php
$user_id = get_the_author_meta('ID');
$registration_date = get_the_author_meta('user_registered', $user_id);
echo '用户注册时间:' . date('Ymd H:i:s', strtotime($registration_date));
?>
这段代码会获取当前文章或用户页面的作者的注册时间并将其显示出来。您可以根据需要将其放置在合适的位置,以确保在前台显示用户注册时间。
请确保在编辑主题文件之前备份您的网站,以防出现问题。此外,根据您的主题和网站的特定情况,可能需要进一步自定义样式和布局来使注册时间以您喜欢的方式显示在前台。