I've been looking up how to do this myself and that same function shown above everyone keeps suggesting isn't working, perhaps due to a recent update to WP's codebase, I'm not entirely sure. It's a little hackish and it involves editing core files (not good) but it's a work-around solution. Here's the steps:
- Use the same function specified in the original post
- Open /wp-includes/pluggable.php and search for "function get_avatar", this should get you to where the function is defined in the file
Scroll down to just above where the first IMG tag is outputted, you should see this:
$out = str_replace( '&', '&', esc_url( $out ) );
$avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
Just under $out
, add $out = $default;
This basically passes the default image source url (stored in the options table)
So it should look like this:
$out = str_replace( '&', '&', esc_url( $out ) );
$out = $default;
$avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
} else {
$avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
}
return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt);
Again, this isn't ideal obviously because the next time you update WordPress, you'll lose this change. But for the moment it works.
To future visitors looking to not modify core files, you may want to look into filtering the WP function get_avatar
. It seems to do so would require modifying the string supplied in the filter with a regular expression to remove the gravatar domain. I attempted it but suck at regex. :P
var_dump( get_bloginfo( 'template_directory' ) );
return? Also: consider usingget_template_directory_uri()
orget_template_stylesheet_uri()
instead.string(50) "http://website.com/wp-content/themes/mytheme"
i1.wp.com
in my browser, the favicon is the Jetpack logo) or any CDN plugins might be the cause.