0

I need for a specific plugin to override the wordpress function get_avatar() to bind the profile image to an other image with some condition.

How can I do this ? Is there a specific hook or filter to do this ?

0

There is get_avatar filter. codex ref

0

I can ovveride in functions.php the function get_avatar() but the best way seems to use the filter get_avatar.

I found the answer here : https://codex.wordpress.org/Plugin_API/Filter_Reference/get_avatar

0

The avatar function has a filter hook get_avatar. You should use this to filter and replace with your function, like the following example, without logic.

add_filter( 'get_avatar', 'get_avatar', 10, 5 );
/**
 *  Override get_avatar with uploaded avatar else default.
 */
function get_avatar( $avatar, $id_or_email, $size, $default, $alt )
{   
    $avatar = "<img alt='{$alt}' src='{$avatar_path}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
    return $avatar;
}
0

You can use this link

You can use the following filter -

// Apply filter
add_filter( 'get_avatar' , 'my_avatar_func' , 1 , 5 );
 
function my_avatar_func( $avatar, $id_or_email, $size, $default, $alt ) {
// your code here 
}
1
  • That's pretty much the same as all the other answers, isn't it? What's new here?
    – Rup
    Aug 2 '21 at 12:04

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.