Home » Functions » get_avatar

Function Name: get_avatar

The get_avatar function in WordPress retrieves the avatar (profile picture) of a user based on their email address or user ID. This function is commonly used in WordPress themes to display the author’s avatar or the avatar of a commenter.

The get_avatar function takes three optional parameters: user ID or email address, size of the avatar (default size is 96 pixels), and a fallback image URL in case the user doesn’t have an avatar. The function returns the HTML code to display the avatar.

Example Usage:

To display the avatar of the current post author with a size of 150 pixels, you can use the following code:

<?php echo get_avatar( get_the_author_meta( 'ID' ), 150 ); ?>

This will display the author’s avatar with a size of 150 pixels. If the author doesn’t have an avatar, the function will use the default Gravatar image.

Learn More on

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