您可以使用过滤器get_avatar
. 这个$avatar
价值类似于:
<img alt=\'\'
src=\'http://0.gravatar.com/avatar/04ef?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516%3D32&r=G\'
class=\'avatar avatar-32 photo\' height=\'32\' width=\'32\' />
The
DOMDocument
看起来很复杂,但是
stuff done.
add_filter( \'get_avatar\', \'avatar_wpse_119123\', 15, 5 );
function avatar_wpse_119123( $avatar, $id_or_email, $size, $default, $alt )
{
$doc = new DOMDocument;
$doc->loadHTML( $avatar );
$imgs = $doc->getElementsByTagName(\'img\');
if ( $imgs->length > 0 )
{
$url = urldecode( $imgs->item(0)->getAttribute(\'src\') );
$url2 = explode( \'?\', $url ); // roughly, the first part is the avatar, the second is the default avatar
$avatar= "<img src=\'$url2[0]?s=30\' alt=\'\' class=\'avatar avatar-30 photo\' height=\'30\' width=\'30\' />";
}
return $avatar;
}
唯一的问题是,这不会影响管理栏用户的菜单。