Title: Custom Avatar Shortcode
Last modified: August 21, 2016

---

# Custom Avatar Shortcode

 *  Resolved [graemebryson5](https://wordpress.org/support/users/graemebryson5/)
 * (@graemebryson5)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/custom-avatar-shortcode/)
 * I’m using the following shortcode to pull in user avatars for a front-end dashboard
   in conjunction with ‘WP User Avatar’, which allows users to set their own avatar.
   I’ve set a new avatar for myself, yet I’m still seeing the default Mystery Man.
 * I wanted to know if anyone could perhaps spot any issues/conflicts that would
   stop the custom avatar being displayed? I’m completely stumped, so would massively
   appreciate some opinions.
 *     ```
       // User Avatar
       add_shortcode( 'current-avatar' , 'ss_get_current_avatar' );
       function ss_get_current_avatar(){
           $user = wp_get_current_user();
           echo get_avatar( $id_or_email, $size, $default, $alt );
       }
   
       // Add class to avatar
       add_filter('get_avatar','add_gravatar_class');
   
       function add_gravatar_class($class) {
           $class = str_replace("class='avatar", "class='avatar welcome_avatar", $class);
           return $class;
       }
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/custom-avatar-shortcode/#post-4771037)
 * Your problem is mostly with this line: `echo get_avatar( $id_or_email, $size,
   $default, $alt );`. You apparently just copied a generic example with placeholder
   parameters. Your function needs to assign real values to these variables, or 
   at least the first one, which is required. The others can be deleted if you are
   happy with the defaults.
 * This replacement line should work for you
    `echo get_avatar( $user->ID );` assuming
   you have “show avatars” checked in your settings.
 * This post is for the proper use of `get_avatar()`. I’m unfamiliar with “WP User
   Avatar”. I would assume it works with `get_avatar()`, but I don’t know for sure.`
   get_avatar()` does work with the gravitar site by default. In the default situation
   users go to the gravitar site to set their avatar and it is used by `get_avatar()`.
 *  Thread Starter [graemebryson5](https://wordpress.org/support/users/graemebryson5/)
 * (@graemebryson5)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/custom-avatar-shortcode/#post-4771060)
 * Hi bcworks,
 * Seriously, thank you. I had just copied over the line with the parameters from
   the Codex – I’ve literally just started out with PHP so didn’t know any better
   aha! I really appreciate your help, have a great weekend!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Avatar Shortcode’ is closed to new replies.

## Tags

 * [get_avatar](https://wordpress.org/support/topic-tag/get_avatar/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [graemebryson5](https://wordpress.org/support/users/graemebryson5/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/custom-avatar-shortcode/#post-4771060)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
