Clearing hard-coded sizes from Avatars

[ad_1]

I want to clear the hard-coded height & width from avatar images, so I can control them with CSS.

I have this code in my WP template:

<?php echo get_avatar( get_the_author_meta( 'ID' ), $size="", $default="", $alt="", $args = array( 'class' => 'pti-author-mug' ) ); ?>

Which returns, in the post:

<img src="http://mysite.org/wp-content/uploads/ultimatemember/2/profile_photo-190x190.jpg?1679782731" class="gravatar avatar avatar-96 um-avatar um-avatar-uploaded" width="96" height="96" alt="Tess Intern" data-default="http://mysite.org/wp-content/plugins/ultimate-member/assets/img/default_avatar.jpg" onerror="if ( ! this.getAttribute('data-load-error') ){ this.setAttribute('data-load-error', '1');this.setAttribute('src', this.getAttribute('data-default'));}">

Because there are um-avatar and um-avatar-uploaded classes, I assume UM is filtering the output of get_avatar. After some rummaging around, I added the following to my functions.php file:

// add_action("init", "um_101821_one_user_avatar_compatibility");
function um_080621_one_user_avatar_compatibility(){
    remove_filter( 'get_avatar', 'um_get_avatar', 99999, 5 );
    remove_filter( 'get_avatar_url', 'um_filter_get_avatar_url', 20, 3 );
    remove_filter( 'avatar_defaults', 'um_avatar_defaults', 99999 );
}

// Remove height/width attributes on avatar img tags.

function myscript_remove_dimensions_avatars( $avatar ) {
    $avatar = preg_replace( "/(width|height)=\'\d*\'\s/", "", $avatar );
    return $avatar;
}

add_filter( 'get_avatar', 'myscript_remove_dimensions_avatars', 10 );

but this seems to have no effect. Am I missing something?

  • This topic was modified 17 hours, 53 minutes ago by theotherdon.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer