How to translate usernames in multilingual WordPress websites

Khalid AlnajjarWordPress Leave a Comment

If you are running multilingual WordPress website and want to display a user’s name differently for some languages, you have landed on the solution to achieve just that. I needed to show different username for my Arabic blog, as Arabic has different letters than Latin.

Based on my research, there are two solutions. The first is to purchase and subscribe to WPML’s Multilingual CMS, which costs $79 (for first year, then it is $39) at the time of writing. The other option is free which is using Polylang. Polylang is a free WordPress plugin and, in my opinion, is the best free multilingual translation plugin available right now.

In this post, I will describe the free solution, using Polylang. Translating usernames isn’t yet implemented in Polylang. So the solution I will provide is kind of a hacky one.

Polylang provides you the ability to translate user’s descriptions. We will utilize this feature and replace user’s display name with user’s description. Below is an image of Polylang’s user biographical info:

A screenshot of user's biographical information forms in WordPress

Translating user’s
biographical information

Go ahead and write your desired username translations in user’s bio info forms which can be found in Your Profile (or All Users then select the user’s profile) under User’s admin panel.

We are almost done. All what is left now is to insert the below snippet at the bottom of the activated theme’s function.php.

add_filter( 'the_author', function( $name ) {
  return trim(wp_strip_all_tags(get_the_author_meta( 'description' )));
});

 

Woohoo, you should now see the new translated usernames.  The main limitation of this solution is that you no longer will be able to use user’s descriptions as descriptions.

I hope that this solution helps you translate user’s display name .

* (This post contains affiliate links. Please read my disclosures for more details).

Share this Post