How to prevent a specific users's profile photo (gravatar) from showing on the frontend to other users?

Yes, I need a code to do that. Plugin is not an option, I need to use theme's functions.php file.

Maybe this filter would help:

apply_filters( 'get_avatar', string $avatar, mixed $id_or_email, int $size, string $default, string $alt, array $args )

I have the user ID.

Topic gravatar users Wordpress

Category Web


Use this hook function to replace user's avatar (which is passed in as HTML <img ...> tag) if user's ID or email matches your condition. You can use any other default image, or get individual replacement image for each user.

function my_get_avatar($avatar, $id_or_email, $size, $default, $alt) {
    if ($id_or_email == "[email protected]") {
        $img = "http://path.to/default/avatar.jpg";
        $avatar = "<img src='".$img ."' alt='".$alt."' height='".$size."' width='".$size."' />";
    }
    return $avatar;
}
add_filter('get_avatar', 'my_get_avatar', 10, 5);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.