Home » Functions » get_avatar_url

Function Name: get_avatar_url

In WordPress, the get_avatar_url function is used to retrieve the URL of the avatar (profile picture) for a specified user email or user ID. It allows developers to programmatically retrieve the avatar URL instead of relying on the default avatar implementation provided by WordPress.

The function takes two parameters: $id_or_email and $args. The $id_or_email parameter can be either the user ID or the user email for which you want to retrieve the avatar URL. The $args parameter is optional and allows you to pass additional arguments to customize the avatar URL.

The get_avatar_url function first checks if the $id_or_email parameter is a valid user email. If it is, it retrieves the user’s avatar URL based on the email. If the $id_or_email parameter is a user ID, it retrieves the avatar URL based on the ID. If the $id_or_email parameter is neither a valid email nor a valid user ID, the function returns false.

Here’s an example usage of the get_avatar_url function:

$user_email = '';
$avatar_url = get_avatar_url($user_email);
echo $avatar_url;

In this example, we specify the user email ‘’ as the $id_or_email parameter. The get_avatar_url function will retrieve the URL of the avatar associated with this email and store it in the $avatar_url variable. Finally, we echo the avatar URL.

By using the get_avatar_url function, developers have more control over how avatars are displayed on their WordPress websites. They can customize the avatar URL retrieval process and integrate it into their own themes or plugins, providing a more tailored user experience.

Remember, when using this function, make sure to sanitize and validate user inputs to ensure security and prevent any vulnerabilities in your WordPress website.

Learn More on

WordPress snippets using the get_avatar_url function

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