How to filter get_avatar?

The Original Poster was missing the pair priority, parameters when declaring the filter hook: add_filter( ‘get_avatar’, array( $this, ‘get_avatar’ ), 10, 5 ); Being 5 all the parameters the callback function can use: public function get_avatar( $avatar, $id_or_email, $size, $default, $alt ) { return $avatar; }

Add aditional class to get_avatar when showing image

I had this problem, too. Here’s the solution for version 4.7.3 if anyone comes across this. get_avatar( $id_or_email = get_the_author_meta( ‘user_email’ ), $size=”60″, $default, $alt, $args = array( ‘class’ => array( ‘d-block’, ‘mx-auto’ ) ) ); or shorter version get_avatar( get_the_author_meta( ‘user_email’ ), ’60’, $default, $alt, array( ‘class’ => array( ‘d-block’, ‘mx-auto’ ) ) ); … Read more

How to display random users with avatars

I am not sure why your query is returning more IDs than necessary. The $args for get_users look correct. By default get_users does not support orderby=rand, but you can overwrite that option. See below: function random_user_query( &$query ) { $query->query_orderby = “ORDER BY RAND()”; } // Usage: [random_users how_many = 3] add_shortcode( ‘random_users’, ‘display_random_users’ ); … Read more

What should I do to make generated avatars different for anonymous comments?

There are two ways to customize the default avatar: Add a new default avatar to Settings/Discussion. Change the output of get_avatar(). Let’s start with the first option; this processes slightly faster. Add a new default avatar to Settings/Discussion There is a filter ‘avatar_defaults’. You can add more avatars here. You get an array of default … Read more

Set default avatar network-wide

The avatar_default is the better option. add_filter(‘pre_option_avatar_default’, ‘se72578_avatar_default’); function se72578_avatar_default( $option ){ return ‘http://example.com/your/default/here.jpg’; } Simple. Stick that in a mu-plugin and you’re good to go. Edit: If you want to still allow site owners to change the default avatar, use the default_option_avatar_default hook instead.

How to change user`s avatar?

Avatars are meant to be controlled by the user, not by you. So yes, in a way, you’re being forced to use the Gravatar service. But remember, it gives the user the ability to use the same avatar anywhere, and you can always restrict the display of a gravatar based on content ratings (G, PG, … Read more

Alternative to using get_avatar function?

The get_avatar() function applies a get_avatar filter hook, that you can use to change the avatar markup: return apply_filters(‘get_avatar’, $avatar, $id_or_email, $size, $default, $alt); I think this would be the correct way to hook into this filter: function mytheme_get_avatar( $avatar ) { $avatar=”<img src=”https://wordpress.stackexchange.com/questions/22728/<” . get_template_directory_uri() . ‘/images/authors/’ . get_the_author_ID() . ‘.jpg” alt=”‘ . get_the_author() … Read more