Is there any function in WordPress that allows to hide the gravatar if id doesn’t exists?
I have many authors that doesn’t have a gravatar and all are displayed like this:
http://prntscr.com/98zsji
I would like to hide the default image.
I used the function validate_gravatar($email);
, but it generated an error:
Fatal error: Call to undefined function validate_gravatar()
If I print $user_email
it display correctly the user email.
You can use validate_gravatar which takes in the email address of the user and returns back true or false.
How to use it in your code:
Here is the filter that will do the trick:
To work you have to add value
404
as third argument$default
toget_avatar()
. Example:I have been using the code below for a while and always work for me. The code is checked with PHPCS and WordPress Theme Standards and there is no errors or warnings.
The script profile-image.js is only enqueued on the respective page user-edit.php, that also applies for the media-upload and Thickbox scripts, this procedure will avoid any possible scripts conflict on your WordPress admin area.
profile-image.js: