Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add ClassName to am avatar


  • eigodeasobo
    Participant

    @eigodeasobo

    Is there a way to add a ClassName to an avatar by <?php bp_displayed_user_avatar('width=150');?> output?

    <img src="//www.gravatar.com/avatar/u965b0sa9cb879767d4g16f1cba90fbb?s=50&r=g&d=identicon" class="avatar user-1-avatar avatar-150 photo" alt="「taro」さんのプロフィール写真" width="150" height="50">

    ↓ add “newclass”

    <img src="//www.gravatar.com/avatar/u965b0sa9cb879767d4g16f1cba90fbb?s=50&r=g&d=identicon" class="newclass avatar user-1-avatar avatar-150 photo" alt="「taro」さんのプロフィール写真" width="150" height="50">

Viewing 5 replies - 1 through 5 (of 5 total)

  • Prashant Singh
    Participant

    @prashantvatsh

    jQuery('.avatar').addClass('newclass');

    Hi,

    You can do it with this simple jquery code.

    Thanks


    eigodeasobo
    Participant

    @eigodeasobo

    Thanks for the reply.
    Sorry, I forgot to write.
    I have circumstances and I would like to do it with PHP.


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,
    I know you want to use BuddyPress function only but as an alternative you should use this one if you want to add class there:

    get_avatar( bp_displayed_user_id(), $size = '150', 'default_image_url', 'alt_text', $args = array( 'class' => array( 'newClass' ) ) );

    For other solution, paste the following in your child theme’s functions.php file:

    add_filter( 'bp_get_displayed_user_avatar', 'bp_get_displayed_avatar_class',10,3 );
    function bp_get_displayed_avatar_class ($avatar, $r, $args){
    	$args['class'] = 'newClass';
    	return $avatar;
    }

    and keep your code same bp_displayed_user_avatar('width=150');

    Thanks


    eigodeasobo
    Participant

    @eigodeasobo

    I see.
    You’re always so reliable.
    Thanks!


    Prashant Singh
    Participant

    @prashantvatsh

    Thanks 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar