• Resolved graemebryson5

    (@graemebryson5)


    I’m using the following shortcode to pull in user avatars for a front-end dashboard page in conjunction with WP User Avatar. I’ve set a new avatar for myself on my profile page, yet I’m still seeing the default Mystery Man on the page using my shortcode.

    Are there any issues/conflicts between the shortcode/plugin that would stop the custom avatar being displayed? I’m not sure why it wouldn’t pull in my custom avatar?

    // 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;
    }

    Thanks for your help!

    https://ww.wp.xz.cn/plugins/wp-user-avatar/

Viewing 2 replies - 1 through 2 (of 2 total)
  • You have to set the variables for get_avatar. Right now, they have no values.

    function ss_get_current_avatar(){
        $user = wp_get_current_user();
        echo get_avatar($user->ID, 96);
    }

    Your second function also won’t work unless you flip the single and double quotes.

    function add_gravatar_class($class) {
        $class = str_replace('class="avatar', 'class="avatar welcome_avatar', $class);
        return $class;
    }
    Thread Starter graemebryson5

    (@graemebryson5)

    Hi Bangbay,

    Thanks for your help, it’s working perfectly now!

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

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