WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Remove Gravatar calls from pluggable.php?

[Resolved] Remove Gravatar calls from pluggable.php?

  • I noticed that on two web sites I manage that the page loads always hang on the Gravatar.

    Neither site has a blog but uses Wordrpress as a CMS. I opened as many files as I thought necessary and see pluggable.php is the one that contains the gravatar links.

    Since I don’t actually need Gravatars, can I just remove the six references to Gravatar?

    Lines are 1703, 1706, 1708, 1712, 1715, and 1717. I realize that I will probably need to do this over again when WP is updated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • No need to hack core. The function you’re looking at, get_avatar(), provides two options for changing what displays for the avatars.

    1. get_option('show_avatars') at the start. Turn this option off to disable all avatars. No Gravatar images will be outputted.
    2. apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt); at the end. This allows you to override the generated HTML with anything you want. No actual calls are made to gravatar in the get_avatar() function. Instead, the calls are made when a gravatar URL is outputted in HTML. This filter allows you to change that HTML before it’s put on the page.

    You can find examples of using that filter to override avatar behavior here and here.

    Turning off the avatars didn’t help. I still get read 1.gravatars.com in the progress bar. I removed a div from two of the page templates to see if that helped but it didn’t either.

    add_filter('get_avatar', 'get_no_gravatar', 1, 2);
    function get_no_gravatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
       // put your new function in here
            $avatar = "<img alt='image_alt' src='#' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
    	return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt);
    };

    From another post, I put this in theme functions and it worked. The page no longer hangs on gravatar.com

    Looks good, but you might want just return $avatar. I would think running apply_filters('get_avatar') inside a function that’s applied to that hook would cause an infinite loop.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Remove Gravatar calls from pluggable.php?’ is closed to new replies.
Skip to toolbar