How to customize the default avatar in WordPress by Bas Wijdenes

Why can’t I customize the Avatar by default in WordPress?

I have no idea why you can not change this by default. You would expect that there is an upload tool, or that you can make an image the default avatar image.

There are different ways to use a different default Avatar in WordPress.
For example, there are many WordPress plugins available that can help you with this, such as the WP User Avatar Plugin. I have something against the use of Plugins when it can be done differently.
After all, you never know what else the plugin does in your environment.


Let’s Customize the default Avatar in WordPress.

You should always use a child theme in WordPress, any changes made to the core will be reset with a WordPress update and it can also malfunction your WordPress website.


The necessities before we start.

You can also change the default avatar in WordPress within your functions.php.
To this you must meet a number of requirements:

  • The best thing is to use a Child theme, so that your modifications remain after updating WordPress.
  • I also use an FTP client like Filezilla and a file editor like Notepad++ to make it easier to make adjustments.

The adjustments.

Start the FTP client or use the WordPress editor.
Make sure you have opened the child theme directory and create a new file named functions.php here. If you already have one, you can proceed to the next step.

We first need to add a code snippet so that your child theme functions.php also uses the code of your original functions.php.
Open the newly created functions.php and copy / paste the following snippet in functions.php.

<?php 
   function twenty_fifteen_child_styles() {
      wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
   }
   add_action( 'wp_enqueue_scripts', 'twenty_fifteen_child_styles' );

If you then add this code snippet, your WordPress site will get a new default avatar.

function baswijdenes ($avatar_defaults) {
   $myavatar = get_bloginfo('stylesheet_directory') . '/images/bas.png';
   $avatar_defaults[$myavatar] = "My own Avatar";
   return $avatar_defaults;
} 

As you can see above, I call the function baswijdendenes. That does not matter much, so you can adjust it to what you want.
The directory where I get the image bas.png is in the core directory, and then a folder called images. The location can be adjusted to what you want. This can also be a direct link to an image.
Here below the complete functions.php.

<?php 
   function twenty_fifteen_child_styles() {
      wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
   }
   add_action( 'wp_enqueue_scripts', 'twenty_fifteen_child_styles' );

   function baswijdenes ($avatar_defaults) {
      $myavatar = get_bloginfo('stylesheet_directory') . '/images/bas.png';
      $avatar_defaults[$myavatar] = "My own Avatar";
      return $avatar_defaults;
   }
?>

The conclusion.

Do you see how easy it is to change the default Avatar in WordPress? You often see plugins for this kind of things, while you can easily do this yourself.
I do not want to say that you should never use a plugin, but always check first if it is possible without a plugin.


Summary

I have reviewed this blog post and I no longer think that the content is very relevant, but because some will still search for this, I keep the blog post for now. I have renewed the post.


Banner image credits

Banner Image by simplu27 from Pixabay.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

Leave a Reply

Your email address will not be published. Required fields are marked *