I have searched and cannot find anything regarding this.

What I want to do is only show part of the users logged in name or username when they leave a comment (it is actually a product review but it uses the comments system).

I need something like what eBay does where is shows something like a*******z.

Is there any code or settings I can change to achieve this?

Thanks in adavance.


You have to dive into comment template in your theme and find out the line where username is printed. Then use the following function in functions.php:

function alter_username( $username ){
    return substr( $username, 0, 1 ). str_repeat( '*', strlen( $username ) - 2 ) . substr( $username, strlen( $username ) - 1 ,1 );

Then use the function in comment template or wherever you want to show altered username like:

echo alter_username( $username );

You will need to use combination of substr and str_repeat PHP functions to achieve this. Although it's very simple.


    function hide_username( $username ) {
        $stringlen = strlen( $username );
        return substr( $username, 0, 1 ) . str_repeat( '*', $stringlen - 2 ) . substr( $username, $stringlen - 1, 1 );

    $username = 'roberthue';
    echo hide_username( $username );


Now if username is roberthue then it will print r*******e.

I was testing it and it's working as advertise. To use this on comment author names, You will have to modify your comment list function. I was using twentytwelve theme, it has twentytwelve_comment function to print comment list but it could be different for you if you are using custom or commercial theme. In your comment list function you will find get_comment_author_link() to print author name and link.

You can replace it with get_comment_author_link().

hide_username ( get_comment_author() )

Login to WordPress dashbord, and choose the right user and select the proper value of 'Display name publicly as' as your wish for every user. If there are a lot of users, simply modify your code from the_author to the_author_meta('first_name'). Here you can change 'first_name' to something else as given in the function reference page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.