I’m using the avatar_defaults filter hook to filter the default avatar list. For example:

function my_avatar_defaults( $avatar_defaults ) {
    $avatar_defaults['http://example.com/foo.png'] = __( 'Foo' );
    return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'my_avatar_defaults' );

This works because if I visit Settings > Discussion and then scroll down, I can see Foo has been added as a default avatar option. See the following screenshot for an example:

Default avatar list of options

The problem is the src attribute of the image displayed next to Foo. It seems to be making a call to Gravatar. Here’s an example of the source code I’m getting for the image next to Foo:

<img src="https://0.gravatar.com/avatar/efaeb0e0be9922051a1c4ccce766a141?s=32&d=http%3A%2F%2Fexample.com%2Ffoo.png%3Fs%3D32&r=G&forcedefault=1" />

How can I ensure the src attribute points to my image URL instead of the Gravatar URL (which seems to have my image’s URL inside it)?

2 Answers
2

You are doing it correctly.

The call to gravatar.com passes the location of your custom image so that WP can load it. Take a look at the query string in the src, you’ll see your image location. That’s how it works.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *