WordPress: Remove Gravatar

A quick tip to remove default wordpress Gravatar avatar links. “avatar.jpg” is default avatar locates at theme directory/images folder, you can change it to any image you want.

// Remove Gravatar
function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) {

	$default = get_stylesheet_directory_uri() .'/images/avatar.jpg';

	if( $image && strpos( $image, "gravatar.com" ) ){ 

		return '<img class="avatar" src="' . $default . '" alt="avatar" />';
	} else {
		return $image;

	}

}
add_filter('bp_core_fetch_avatar', 'bp_remove_gravatar', 1, 9 );

function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) {

	$default = get_stylesheet_directory_uri() .'/images/avatar.jpg';
	return "<img class="avatar avatar-{$size} photo avatar-default" src="{$default}" alt="{$alt}" width="{$size}" height="{$size}" />";
}

add_filter('get_avatar', 'remove_gravatar', 1, 5);

function bp_remove_signup_gravatar ($image) {

	$default = get_stylesheet_directory_uri() .'/images/avatar.png';

	if( $image &amp;&amp; strpos( $image, "gravatar.com" ) ){ 

		return '<img class="avatar" src="' . $default . '" alt="avatar" width="60" height="60" />';
	} else {
		return $image;
	}

}
add_filter('bp_get_signup_avatar', 'bp_remove_signup_gravatar', 1, 1 );