The get_avatar_url
filter you are using only affects the avatar URL generated by the get_avatar_url
function. The wp_list_comments
function, on the other hand, uses the get_avatar
function to generate the avatar HTML, which does not go through the get_avatar_url
filter.
To modify the avatar displayed in comments, you can use the get_avatar_data
filter, which is called by the get_avatar
function and allows you to modify the data used to generate the avatar HTML. Here's an example of how you can use it:
add_filter( 'get_avatar_data', 'my\plugin\filter_get_avatar_data', 10, 2 );
function filter_get_avatar_data( $args, $id_or_email ) {
// Modify the avatar data as needed
$args['url'] = 'https://example.com/my-custom-avatar.png';
return $args;
}
In this example, the get_avatar_data
filter is used to modify the avatar data by changing the url
parameter to the URL of a custom avatar image. You can modify the avatar data in any way you need, and the modified data will be used to generate the avatar HTML.
Note that the get_avatar_data
filter is called with two parameters: $args
, which is an array of arguments used to generate the avatar, and $id_or_email
, which is the user ID or email address associated with the avatar. You can use these parameters to modify the avatar data as needed.
Keep in mind that modifying the avatar HTML in comments can be tricky, as comments may be cached by WordPress or by third-party caching plugins, so your changes may not be immediately visible. Additionally, modifying the avatar data may also affect other parts of your site that use the get_avatar
function, so be sure to test thoroughly.
Reference:
https://developer.wordpress.org/reference/hooks/get_avatar_data/