Question

Is there any way to change the aspect ratio of the WordPress Avatars? Or is this hardcoded?

Was it helpful?

Solution

Possible sollutions:

  • Use Css with something like overflow: hidden; and "cut out" what you need.
  • Use the filter apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt); and override the output of $avatar completely.
  • The function get_avatar() is pluggable. That means if you hook a plugin function early enough that already defines get_avatar() then this function will be used instead of the core function. See Core (link).

OTHER TIPS

The aspect ratio is dictated by the Gravatar service and it's not customizable.

It's a bit of a hack, but you can hard-code a new crop ratio by changing line 566 of wp-content/plugins/buddypress/bp-core/js/avatar.js from...

aspectRatio: self.options.aspectRatio,

...to...

aspectRatio: 1.72817,

... replacing 1.72817 with the aspect ratio of your choice of course.

Note you will also have to edit the same bit in avatar.min.js for it to work.

As it is a hack, you will have to be careful when updating Buddypress and you may have to keep re-applying the change. So if you can do it without hacking the core files then do that!

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top