Adding a default Gravatar in WordPress
Ce contenu n’est pas encore disponible dans votre langue.
WordPress uses Gravatar (Globally Recognized Avatar) to display user profile images beside comments and posts. By default, WordPress provides a set of placeholder avatars. On ruachost.com, you can replace this with a custom default gravatar that better represents your brand or site.
Why Add a Custom Default Gravatar?
Section titled “Why Add a Custom Default Gravatar?”- Strengthens brand identity by showing a logo or custom image.
- Improves site aesthetics compared to generic placeholders.
- Provides a consistent look for users without personal gravatars.
Steps to Add a Default Gravatar
Section titled “Steps to Add a Default Gravatar”1. Upload Your Image
Section titled “1. Upload Your Image”- Log in to WordPress with an administrator account.
- Go to Media → Add New.
- Upload your custom gravatar image.
- Click on the image → Copy the File URL.
2. Add Code to functions.php
Section titled “2. Add Code to functions.php”-
In the dashboard, go to Appearance → Theme Editor.
-
Select your active theme and open the functions.php file.
-
Add the following code snippet:
// Add custom default gravataradd_filter( 'avatar_defaults', 'ruachost_custom_gravatar' );function ruachost_custom_gravatar( $avatar_defaults ) {$myavatar = 'https://yourdomain.com/wp-content/uploads/2025/11/custom-gravatar.png';$avatar_defaults[$myavatar] = "Default Gravatar";return $avatar_defaults;}- Replace the URL with the File URL copied from your Media Library.
-
Save the file.
3. Select Your New Default Gravatar
Section titled “3. Select Your New Default Gravatar”- Go to Settings → Discussion.
- Scroll down to the Default Avatar section.
- Select your new gravatar option.
- Click Save Changes.
✅ Your custom gravatar will now appear for users without a personal avatar.
Important Notes
Section titled “Important Notes”- Always back up your theme before editing
functions.php. - Use a child theme to preserve changes during updates.
- Ensure the image is square (e.g., 200×200 px) for best results.
Cette page vous a-t-elle aidé ?
Merci pour votre retour.