Notifications
Clear all

[Solved] How to change the Nicename that appears in the comments to the FirstName?

7 Posts
2 Users
1 Reactions
1,121 Views
(@mariia-smolina)
Member Customer
Joined: 5 years ago
Posts: 9
Topic starter  

Good afternoon.
How to make the comments display not the Display Name / Nicename, but the First Name and first letter of the Last Name?


   
Elvina
(@elvina)
Support
Joined: 5 years ago
Posts: 1403
 

Hi @mariia-smolina,

Please put the following code in the functions.php file of the current active theme.

add_filter('wpdiscuz_comment_author', function ($authorName, $comment){
if ($comment->user_id) {
$first = get_user_meta($comment->user_id, 'first_name', true);
$last = get_user_meta($comment->user_id, 'last_name', true);
if ($first) {
$authorName = $first;
if ($last) {
$authorName .= ' '. substr($last, 0, 1) . '.';
}
}
}
return $authorName;
}, 10, 2);

   
(@mariia-smolina)
Member Customer
Joined: 5 years ago
Posts: 9
Topic starter  

great work! thank you!


   
Elvina reacted
Elvina
(@elvina)
Support
Joined: 5 years ago
Posts: 1403
 

@mariia-smolina,

We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.


   
(@mariia-smolina)
Member Customer
Joined: 5 years ago
Posts: 9
Topic starter  

one more question.

not immediately noticed. For some reason, the first letter of the last name is displayed as a question mark for all users
example Мария �.

exeple page https://smollydolls.ru/priglashenie-na-onlajn-po-vjazaniju/


   
Elvina
(@elvina)
Support
Joined: 5 years ago
Posts: 1403
 

@mariia-smolina,

Please try the following one:

add_filter('wpdiscuz_comment_author', function ($authorName, $comment){
if ($comment->user_id) {
$first = get_user_meta($comment->user_id, 'first_name', true);
$last = get_user_meta($comment->user_id, 'last_name', true);
if ($first) {
$authorName = $first;
if ($last) {
$authorName .= ' '. mb_substr($last, 0, 1) . '.';
}
}
}
return $authorName;
}, 10, 2);

   
(@mariia-smolina)
Member Customer
Joined: 5 years ago
Posts: 9
Topic starter  

Yes, it helped, thank you very much!


   
Share:
Scroll to top