【问题标题】:How can we display current user display name with shortcode?我们如何使用简码显示当前用户显示名称?
【发布时间】:2020-07-08 10:18:56
【问题描述】:

我得到了这个简码函数来显示当前用户的显示名称,但现在由于某种原因它正在显示用户的名字。还有其他方法可以获取当前用户的显示名称并使用简码输出吗?

// [current_user_display_name]
function display_current_user_display_name () {
    $user = wp_get_current_user();
    $display_name = $user->display_name;
    return $user->display_name;
}
add_shortcode('current_user_display_name', 'display_current_user_display_name');

【问题讨论】:

  • 因为您当然只是简单地将用户名设置为显示名称...
  • 你能为我澄清一下...在我的 woocommerce->users 中,显示名称与名字不同吗?不知道为什么这个函数会调用用户的名字?

标签: php wordpress function woocommerce shortcode


【解决方案1】:

如果您转到用户的个人资料(用户 > 所有用户 > 搜索您想要的用户),那么其中一项设置称为“公开显示名称”。从可用的不同选项中可以看出,用户可以将他们的显示名称设置为他们的名字。如果您希望简码显示用户名,请使用$user->user_login。如果您想要名字和姓氏,可以从get_user_meta( $user->ID ) 获取该信息。

使用名字和姓氏时要小心,因为并非所有用户都会保存名字和姓氏。当没有名字或姓氏时,我通常会使用用户名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    • 2011-10-05
    • 1970-01-01
    • 2013-05-15
    • 2022-12-30
    相关资源
    最近更新 更多