Home » Functions » translate_user_role

Function Name: translate_user_role

Explanation: The translate_user_role function is a WordPress function used to translate the display name of a user role into the desired language. It retrieves the translated version of a user role’s display name based on the provided role and desired language.

This function is particularly useful in multilingual websites or applications where user roles need to be displayed in different languages based on the user’s language preference.

Parameters: The translate_user_role function accepts two parameters:

  1. $role (string) – The user role to be translated.
  2. $domain (string) – Optional. The text domain to use for translations. By default, it uses the ‘default’ text domain.

Return Value: The function returns the translated version of the user role’s display name if a translation is available. If no translation is found, it returns the original user role name.

Example Usage:

Let’s say we have a WordPress website that is available in multiple languages. We want to display the translated version of the user role "Editor" based on the user’s language preference. Here’s an example usage of the translate_user_role function:

$user_role = 'editor';
$translated_role = translate_user_role($user_role);

echo "Translated User Role: " . $translated_role;

In this example, the translate_user_role function will retrieve the translated display name of the "Editor" role based on the current language settings. If the website is set to display content in French, and a French translation for the "Editor" role is available, it will output "Translated User Role: Éditeur". If no translation is available, it will output "Translated User Role: Editor".

Learn More on

WordPress snippets using the translate_user_role function

Register an account to save your snippets or go Pro to get more features.