1

I've used my own custom plugin for custom functions and I'm trying to change the default WordPress avatar to my own custom avatar.

My plugin name is "ACh-Toolkit".

I used the following functions but none worked!

function ach_avatar( $avatar_defaults ) {
    $avatar = get_option('avatar_default');
    $new_avatar_url = plugins_url() . '/ACh-Toolkit/images/avatar.png';
    if( $avatar != $new_avatar_url )
    {
        update_option( 'avatar_default', $new_avatar_url );
    }
    $avatar_defaults[ $new_avatar_url ] = 'ACh Avatar';
    return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'ach_avatar' );
function ach_gravatar ($avatar_defaults) {
    $myavatar = get_home_url() . plugin_dir_url( __FILE__ ). "images/avatar.png";
    $avatar_defaults[$myavatar] = "ACh Avatar";
    return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'ach_gravatar' );
function ach_gravatar ($avatar_defaults) {
        $myavatar = home_url() . '/wp-content/plugins/ACh-Toolkit/images/avatar.png';
        $avatar_defaults[$myavatar] = "ACh Avatar";
    return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'ach_gravatar' );

Please help me to solve this problem. Thanks

  • It's not a direct answer, but I've used the WP plugin: WP User Avatar (flippercode) successfully. Its functions may be helpful. – Leora Deans Dec 2 '19 at 22:24
  • you can customise the avatar with the filter get_avatar_url – Kaperto Dec 3 '19 at 20:30
  • Please give me an example. – Ali Chopani Dec 3 '19 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.