Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created May 2, 2023 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewlimaza/f696ee7b8727f07ca1f473a0096a87a9 to your computer and use it in GitHub Desktop.
Save andrewlimaza/f696ee7b8727f07ca1f473a0096a87a9 to your computer and use it in GitHub Desktop.
Default Basic User Avatar image when none is found
<?php
/**
* This assumes that Gravatar (or one of it's services is set as the default WP avatar option).
* Adjust this code and insert your own URL to the default avatar.
* Add this code to your site by following a guide like - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_bua_default_avatar_image( $avatar, $id_or_email ) {
if ( strpos( $avatar, 'secure.gravatar.com' ) !== false ) {
$default_avatar = "https://URLTOIMAGE.COM/SOME-PATH/IMAGE.png"; // Change this to the URL for the default AVATAR.
$avatar = "<img src='$default_avatar' srcset='$default_avatar' alt='default avatar' class='avatar avatar-64 photo' height='64' width='64' loading='lazy' decoding='async'/>";
}
return $avatar;
}
add_filter( 'basic_user_avatar', 'my_bua_default_avatar_image', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment