benecaster_avatar_fallback
Filters the avatar URL used when a subscriber has no uploaded avatar and site-wide Gravatar is disabled. Return a fully qualified URL to serve a custom fallback image — for example, an initials-based avatar generated from the subscriber’s display name. Return null to let WordPress fall through to its own default avatar (typically the ‘mystery person’ silhouette).
This filter is bypassed entirely when site-wide Gravatar is enabled. In that case, WordPress’s Gravatar URL is used without calling this filter.
⚠ An empty string is treated exactly like null, not as “render no avatar”. The result is kept only when it is_string() and is non-empty, so '' falls through to the WordPress default. There is no return value that suppresses the avatar entirely, and any non-string return is discarded the same way.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$url |
?string |
— | Current fallback URL — null by default |
$user_id |
int |
— | WordPress user ID |
Returns:
string|null
Examples
Serve initials-based avatar as fallback
add_filter( 'benecaster_avatar_fallback', function ( ?string $url, int $user_id ): ?string {
$user = get_userdata( $user_id );
if ( ! $user ) {
return $url;
}
$initial = strtoupper( mb_substr( $user->display_name ?: $user->user_email, 0, 1 ) );
// Return a URL to your initials image generator service
return 'https://example.com/avatars/initials?letter=' . urlencode( $initial );
}, 10, 2 );
Need this built rather than just documented? See our services →