username - Change user's display name programmatically

I'd like to change a user's display name using this code snippet in my theme's functions.php file:$user_i

I'd like to change a user's display name using this code snippet in my theme's functions.php file:

$user_id = 672;
$display_name= 'Les Yeux';

$user_id = wp_update_user( array( 'ID' => $user_id, 'display_name' => $display_name ) );

This is adapted from this topic in the codex:

But I can't get it to work. It didn't change anything. Did I miss something?

I'd like to change a user's display name using this code snippet in my theme's functions.php file:

$user_id = 672;
$display_name= 'Les Yeux';

$user_id = wp_update_user( array( 'ID' => $user_id, 'display_name' => $display_name ) );

This is adapted from this topic in the codex: https://codex.wordpress/Function_Reference/wp_update_user

But I can't get it to work. It didn't change anything. Did I miss something?

Share Improve this question edited Oct 29, 2019 at 9:29 the 1,5682 gold badges13 silver badges32 bronze badges asked Dec 12, 2015 at 15:19 Graham SlickGraham Slick 2712 gold badges4 silver badges13 bronze badges 8
  • How are you checking the results? Are you looking at the database directly? What? And what is the point? This is value is trivial to change from the backend. Why do you need to cook up this piece of code? – s_ha_dum Commented Dec 12, 2015 at 15:45
  • @s_ha_dum I had an issue with my site, some users don't have a display name for a reason that I ignore. The result is that their profile doesn't have a name on it (look at the name of your browser tab for example): ouiaremakers/utilisateur/672 comparing to ouiaremakers/utilisateur/1 I'm trying to fix this by changing their display_name (which is what is supposed to appear on their profile), bc nothing works from the back office – Graham Slick Commented Dec 12, 2015 at 15:59
  • Ok. That information helps but you did not answer the first question: How are you checking the results? – s_ha_dum Commented Dec 12, 2015 at 16:04
  • 1 @s_ha_dum Nothing changes on these profiles ... I tried with the profile I sent you and it didn't display a name – Graham Slick Commented Dec 12, 2015 at 16:11
  • 1 And you are still not answering the question! How are you checking? Are you looking at the database via PHPMyAdmin or other tool? Are you just looking at the generated page? Are you using some function to check the user data? How? What is the mechanism you are using to determine that the wp_update_user() code doesn't work? – s_ha_dum Commented Dec 12, 2015 at 16:14
 |  Show 3 more comments

1 Answer 1

Reset to default 3

Just pasted your code into my functions.php with a different ID and checked the user's page in /wp-admin/user-edit.php - it works, the value in Display name publicly as field is updated.

Most likely something is wrong with your output on the user page. Check your template file. Or, if you can't find the problem, edit the question and update it by pasting only the relevant code from your template - not the entire template.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745047262a4608176.html

相关推荐

  • username - Change user's display name programmatically

    I'd like to change a user's display name using this code snippet in my theme's functions.php file:$user_i

    7小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信