Prevent WordPress from Showing an Email Address as a Commenter’s Name
Depending on how your WordPress site is setup, and especially if you have a Woocommerce shop where users are automatically registered and then their email address is used to populate their username, you may find that your customer’s email addresses are being displayed when they leave a comment or review.
That’s no good!
Here’s some code that might get you moving in the right direction:
<?php $modified_comment_author = get_comment_author(get_comment_ID());
if (strpos($modified_comment_author, '@') !== false) {
$modified_comment_author = substr($modified_comment_author, 0, strpos($modified_comment_author, "@"));
} ?>
Then you can use < echo $modified_comment_author; ?>
wherever the commenter’s name is displayed, often in a custom callback or special theme file.
All this really does is remove the @somewebsite.com part of their name, so if their email was example@gmail.com, it will now just display “example.”