Change the default profile picture for users who don't have a Gravatar (3 posts)

  1. ido_doron
    Posted 3 years ago #

    Hi, I want to replace the default "Mystery Man" profile picture with a different picture.

    As you know, you can access someone's Facebook profile picture by going to http://graph.facebook.com/<USER ID>/picture (replace <USER ID> with the UID of the requested account.

    So what I basically did was adding my theme's function file these few lines:

    add_filter( 'avatar_defaults', 'newgravatar' );  
    function newgravatar ($avatar_defaults) {
        $myavatar = 'http://graph.facebook.com/'.get_current_user_id().'/picture';
        $avatar_defaults[$myavatar] = "FB Profile Picture";
        return $avatar_defaults;

    The problem is that wordpress doesn't show this URL directly. It stores the picture on WordPress.com's servers. As a result, the picture is always the same picture and doesn't change when a different user logs in.

    Is there any way to prevent WordPress from caching the picture on their servers? Or is there any other way to do what I want to do?

  2. bcworkz
    Posted 3 years ago #

    Yes, there is a way. You essentially just hooked the wrong filter. You want 'get_avatar'. Your hook function is passed a bunch of useful data, based on that, you return the html required to show the desired avatar image. See line 1668 of wp-includes/pluggable.php .

  3. rerartist
    Posted 3 years ago #

    I just stumbled onto this post, but hopefully a late reply is better than no reply at all.

    This tutorial shows you how to create a gravatar in Photoshop, AND includes instructions for implementing it. NOTE - you should be using a Child Theme for all modifications. Besides the style.css, you will need to put a functions.php in your child theme directory.

    Create Your Own Image to Change The Default Gravatar in WordPress

Topic Closed

This topic has been closed to new replies.

About this Topic