Good afternoon.
How to make the comments display not the Display Name / Nicename, but the First Name and first letter of the Last Name?
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);
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.
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/
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);
Yes, it helped, thank you very much!