Change wordpress default avatar with custom plugin

Question

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

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/change-wordpress-default-avatar-with-custom-plugin/">

Change wordpress default avatar with custom plugin</a>
0
Ali Chopani 6 months 0 Answers 38 views 0

Leave an answer