Codex tools: Log in
Languages: English • 日本語 • (Add your language)
Contents |
Retrieve the avatar for a user who provided a user ID or email address. Most commonly used in the comments section.
This function is pluggable, however plugin authors wishing to change the gravatar output should use the get_avatar filter instead, for compatibility purposes.
This function will not return an avatar if "Show Avatars" is unchecked in Settings > Discussion.
<?php echo get_avatar( $id_or_email, $size, $default, $alt ); ?>
$comment here, in order to display the gravatar of the commenter. In other templates within The Loop (for WordPress 2.7 and lower), you can use get_the_author_id() (deprecated in WordPress 2.8). For WordPress 2.8 and up, please use get_the_author_meta('ID').
For comments:
<?php echo get_avatar( $comment, 32 ); ?>
For a post's author, in The Loop:
<?php echo get_avatar( get_the_author_meta('ID'), 32 ); ?>
For a random email address:
<?php echo get_avatar( 'email@example.com', 32 ); ?>
get_avatar() is located in wp-includes/pluggable.php.