Hello,
You can directly use get_avtar() function for the output of avtar.
echo get_avatar($user_id, 80);
Ref : https://developer.wordpress.org/reference/functions/get_avatar/
Hope this helps!
Thanks.
Would that give any different results?
Is the function get_avatar
not relying on the same value returned by the function get_avatar_url
?
The get_avatar()
function can be replaced by a plugin (“pluggable” in WP-speak), and it allows plugins to bypass default avatar processing with the pre_get_avatar
hook. The get_avatar_url()
function does neither, so if you’re using a plugin that replaces get_avatar()
or uses pre_get_avatar
, get_avatar_url()
can return a different URL than the one in the IMG tag returned by get_avatar()
.
Is there a way to get the correct (based on your input) URL without the <img>
tag?
Or is parsing the result the only solution?
If you want the URL to be valid on all sites, I think you’ll need to parse the <IMG>
tag. If this is for your own site, it would be worth locating which plugin is expanding avatar functionality, and checking whether the plugin has its own hook to obtain the URL.
It would be worth trying to use the get_avatar
hook. The avatar URL is passed in the $args
array. Here is the documentation:
https://developer.wordpress.org/reference/hooks/get_avatar/
If a plugin replaces avatar processing, it’s very likely the plugin has made sure this hook works because it’s used by a number of other popular plugins.