特定的用户显示名称由ID和短代码?

发布于 2025-02-02 02:12:36 字数 606 浏览 6 评论 0原文

我一直在尝试多种组合来显示WordPress中ID的特定用户的显示名称,但最后,我无法使其正常工作。我需要帮助。我要使用的代码如下:


function custom_id_display_name($atts, $content = null) {

   extract( shortcode_atts( 
           array('id' => '0',), $atts 
                          ) 
           );

 /*  return $display_name( $user_id, 96 ); // display the specific user_id's name*/
   return get_display_name($atts['id'], 96);
}

add_shortcode('custom_display_name','custom_id_display_name');

“有趣”的事情是,该代码适用于自定义阿凡达,返回不同,

 return get_avatar($atts['id'], 96);

所以我不知道为什么它不适用于显示名称。感谢您的帮助! :-)

I have been trying several combinations for displaying the display name for a specific user by ID in WordPress, but in the end, I couldn't make it work. I need help, please. The code I'm trying to use is the following:


function custom_id_display_name($atts, $content = null) {

   extract( shortcode_atts( 
           array('id' => '0',), $atts 
                          ) 
           );

 /*  return $display_name( $user_id, 96 ); // display the specific user_id's name*/
   return get_display_name($atts['id'], 96);
}

add_shortcode('custom_display_name','custom_id_display_name');

The "funny" thing is that the code worked well for custom avatar with a different return,

 return get_avatar($atts['id'], 96);

so I have no idea why it's not working for the display name. Thanks for your help! :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经大条 2025-02-09 02:12:36

您可以使用get_user_by(字符串$ field,int |字符串$ value) get_user_by 这是 a>引用

You can use get_user_by( string $field, int|string $value ) get_user_by here is the stackoverflow referance

寄居人 2025-02-09 02:12:36

首先,您获取用户对象。

$user = get_user_by( 'ID', $user_id );

然后显示您获得的名称:

$display_name = $user->display_name;

First you get the user object.

$user = get_user_by( 'ID', $user_id );

Then display name you get with:

$display_name = $user->display_name;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文