-
-
Notifications
You must be signed in to change notification settings - Fork 510
Description
Expected behavior
If you want to customize the default avatar in WordPress from a plugin or theme, normally you'd do so via one of the avatar filters like so:
function example_custom_avatar_data($args, $id_or_email) {
$args['default'] = 'https://placeimg.com/96/96/animals';
return $args;
}
add_filter('pre_get_avatar_data', 'example_custom_avatar_data', 10, 2);In which case any request for a Gravatar that does not exist will instead display our custom default image:
This functionality is helpful in cases where we want to extend WordPress's default avatar functionality dynamically via a plugin.
Actual behavior
In Timber, the following code in the context of a post comment…
<img src="{{comment.avatar}}" width="96" height="96" alt="">…will never display the image path set via the filter using $args['default']. It will always fall back to get_option('avatar_default') unless $default is provided from the template.
Steps to reproduce behavior
- Activate the Timber starter theme.
- Add the Twig snippet above to the theme's
templates/comment.twig. - Add the PHP snippet above to the theme's
functions.phpor to a new plugin. - Navigate to
wp-admin/options-discussion.phpand scroll to the "Default avatar" section. All default avatars should display the image path provided in the PHP snippet. - Navigate to a post containing comments with a default image visible. Observe that the image displayed does not match what was defined in the filter.
What version of WordPress, PHP and Timber are you using?
- WordPress 5.7.2
- PHP 7.4.1
- Timber 1.18.2
How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)
- WP.org, synced locally via Local

