# Don't Send Guest Commenters' Emails to Gravatar

> Shows a built-in placeholder avatar for comments from visitors without an account, so their hashed email address is never sent to Gravatar, while registered users keep their Gravatar picture.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: avatars, gravatar, comments
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-local-avatar-for-guests/

## Code

```php
add_filter( 'pre_get_avatar_data', function ( $args, $id_or_email ) {
    $is_guest = false;

    if ( $id_or_email instanceof WP_Comment ) {
        $is_guest = ! (int) $id_or_email->user_id;
    } elseif ( is_string( $id_or_email ) && is_email( $id_or_email ) ) {
        $is_guest = ! email_exists( $id_or_email );
    }

    if ( ! $is_guest ) {
        return $args;
    }

    $svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" fill="#c3c4c7"/><circle cx="32" cy="25" r="12" fill="#fff"/><path d="M12 58c2-13 10-19 20-19s18 6 20 19z" fill="#fff"/></svg>';

    $args['url']          = 'data:image/svg+xml;base64,' . base64_encode( $svg );
    $args['found_avatar'] = true;

    return $args;
}, 10, 2 );
```

## Notes

Change the color in the SVG to match your design; registered users can still be shown with their Gravatar.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Don't Send Guest Commenters' Emails to Gravatar" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
