Change default Gravatar for comments – WordPress
In default, WordPress use mystery man
as Gravatar for comments. But if you like to brand your users default garvatar, we can easily achieve this with a simple function & filter.
First we want to open our functions.php
file in child theme directory. Then add below filter & function on it.
if ( !function_exists('s_addgravatar') ) {
function s_addgravatar( $avatar_defaults ) {
$myavatar = get_bloginfo('template_directory') . '/images/your_avatar.jpg';
$avatar_defaults[$myavatar] = 'Custom Avatar';
return $avatar_defaults;
}
add_filter( 'avatar_defaults', 's_addgravatar' );
}
Then add our branded new avatar image in to child theme’s images
folder & edit the 3rd line of code according to our image name.
We almost completed the coding. Next we want to set up this new avatar as default avatar for discussion in WordPress back-end.
Just go to Settings » Discussion settings & now we can see our new avatar name Custom Avatar
in Default avatar settings. So choose Custom Avatar
as Default avatar & save changes.
Looking for a skilled WordPress/WooCommerce developer? I'm currently available for freelance, contract, or full-time remote opportunities! Let's create something amazing together. Send me a quick message, and I'll respond within 24 hours!
Recent Posts
- Automating Code Linting with GitHub Actions for WordPress Plugins
- Comprehensive Guide to Linting PHP, JavaScript, and CSS in WordPress Plugins Using Composer
- The Ultimate Guide to Indexing in Database Design
- Understanding 'update_meta_cache' in WordPress - When to Use It, When Not to, and Its Impact on Database Queries
- A Guide to Configuring JavaScript and SCSS Paths in WordPress Plugins with @wordpress/scripts
Your Questions / Comments
If you found this article interesting, found errors, or just want to discuss about it, please get in touch.