get_avatar_url

Retrieves the avatar URL.

Description

(false|string) get_avatar_url( (mixed) $id_or_email, (null) $args = null ); 

Returns (false|string)

The URL of the avatar we found, or false if we couldn't find an avatar.

Parameters (2)

0. $id_or_email (mixed)
The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash, user email, WP_User object, WP_Post object, or WP_Comment object.
1. $args — Optional. (null) => null
Arguments to return instead of the default arguments.

Options

  • size (int) => 96

    Height and width of the avatar in pixels.

  • default (string) => 'avatar_default'

    URL for the default image or a default type. Accepts 404 (return a 404 instead of a default image), retro (8bit), monsterid, (monster), wavatar (cartoon face), indenticon (the quilt), mystery, mm, or mysteryman (The Oyster Man), blank (transparent GIF), or gravatar_default (the Gravatar logo).

  • force_default (bool) => false

    Whether to always show the default image, never the Gravatar.

  • rating (string) => 'avatar_rating'

    What rating to display avatars up to. Accepts G,, PG, R, X, and are judged in that order.

  • scheme (string) => null

    URL scheme to use. See set_url_scheme() for accepted values.

array(

    /**
     * Height and width of the avatar in pixels.
     *
     * @type int
     * @default 96
     */
    'size' => 96,

    /**
     * URL for the default image or a default type. Accepts '404' (return a 404 instead of a default
     * image), 'retro' (8bit), 'monsterid' (monster), 'wavatar' (cartoon face), 'indenticon'
     * (the "quilt"), 'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent
     * GIF), or 'gravatar_default' (the Gravatar logo).
     *
     * @type string
     * @default 'avatar_default'
     */
    'default' => 'avatar_default',

    /**
     * Whether to always show the default image, never the Gravatar.
     *
     * @type bool
     * @default false
     */
    'force_default' => false,

    /**
     * What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are judged in that order.
     *
     * @type string
     * @default 'avatar_rating'
     */
    'rating' => 'avatar_rating',

    /**
     * URL scheme to use. See set_url_scheme() for accepted values.
     *
     * @type string
     * @default null
     */
    'scheme' => null
);        


Usage

  1. if ( !function_exists( 'get_avatar_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash, 
  5. // user email, WP_User object, WP_Post object, or WP_Comment object. 
  6. $id_or_email = null; 
  7.  
  8. // Optional. Arguments to return instead of the default arguments. 
  9. $args = array( 
  10. 'size' => 96, 
  11. 'default' => 'avatar_default', 
  12. 'force_default' => false, 
  13. 'rating' => 'avatar_rating', 
  14. 'scheme' => null 
  15. ); 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = get_avatar_url($id_or_email, $args); 
  19.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_avatar_url( $id_or_email, $args = null ) { 
  2. $args = get_avatar_data( $id_or_email, $args ); 
  3. return $args['url'];