Custom avatar support in wordpress?


Most people commenting on blogs online have an avatar associated with them. If, however, they don’t and you don’t particularly like the WordPress default avatar options, you can define your own.
To do so, include the following code in your functions.php:
if ( !function_exists('cake_addgravatar') ) {
 function cake_addgravatar( $avatar_defaults ) {
  $myavatar = get_template_directory_uri() . '/images/avatar.png';
  $avatar_defaults[$myavatar] = 'avatar';
  return $avatar_defaults;
 }
 add_filter( 'avatar_defaults', 'cake_addgravatar' );
}
What we’re doing here first, is checking to see if the function exists. If it does, we add a filter that tells WordPress to use our custom defined avatar as the default.
We are telling WordPress to find this avatar in our “images” directory inside the theme directory. Next step, obviously, is to create the image itself and upload it to the “images” folder.

No comments:

Post a Comment