特定的用户显示名称由ID和短代码?
我一直在尝试多种组合来显示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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
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首先,您获取用户对象。
然后显示您获得的名称:
First you get the user object.
Then display name you get with: