Search
Close
AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

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

7 Posts
2 Users
1 Reactions
2,073 Views
(@mariia-smolina)
Member Customer
Joined: 6 years ago
Posts: 9
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
  [#5929]

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: 7 years ago
Posts: 1403
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

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: 6 years ago
Posts: 9
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

great work! thank you!



   
Elvina reacted
Elvina
(@elvina)
Support
Joined: 7 years ago
Posts: 1403
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@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: 6 years ago
Posts: 9
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

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: 7 years ago
Posts: 1403
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@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: 6 years ago
Posts: 9
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

Yes, it helped, thank you very much!



   
Share:
Scroll to top