Skip to content
Advertisement

Check if a User Has a Gravatar [WordPress]

Thanks Rene Korss for helping to resolve the issue almost and be there every time to reply in discussion.

I want to check if the user who has posted comment is having an avatar or not? If user has avatar (means having gravatar account) show gravatar avatar else show image which I have defined in else portion. Any help would be appriciated.

I am currently using this code:

JavaScript

Output for this code is only else portion working. And in case I am writing condition as if(get_avatar()) then only if portion working.

$comment has values:

JavaScript

When used this code:

JavaScript

Got output like this:

enter image description here

Output for:

JavaScript

is: enter image description here

Advertisement

Answer

Try with this. Using author email should help. Also, notice that I’m not calling get_avatar twice. else is not needed, because you can set $default image to be used, if avatar dosen’t exist.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement