BuddyDev

Search

[Resolved] Get avatar with link to profile

  • Participant
    Level: Master
    Posts: 171
    JohnnyNW on #27335

    Hello.

    I have a small snippet of codeget_avatar($user, 30); that shows user avatar image at 30 pixels in size.

    Could you recommend how I could actually make this avatar image link to the users profile? Right now, it’s just an avatar image.

    Thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #27336

    Hi JJ,
    You can use

    
    bp_core_get_user_domain( $user_id );
    

    to get the url of the user.

    Here is an example.

    
    <a href="<?php echo bp_core_get_user_domain(1);?>">....</a>
    
    

    Hope this helps.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 171
    JohnnyNW on #27342

    Unfortunately, it only shoots back a URL link (that isn’t clickable).

    The actual code piece is this:

    
    foreach ($bookmarked_by as $user) {
    				$avt_list .=  get_avatar($user , 30);
    			}
    

    While it belongs to this:

    
    add_filter( 'the_content', 'wp_bookmark_below_post', 1001 );
    	function wp_bookmark_below_post( $content ) {
    		$post_id = get_the_ID();
    		$post = get_post( $post_id );
    		if($post->post_type=='page'){
    			return $content;
    		}
    		if(wpb_get_option('wpb_show_users_avatar')) {
    			$avt_list = '';
    			$bookmarked_by = get_post_meta($post_id , 'wpb_bookmarked_by' ,true);
    			if($bookmarked_by == '')
    				$bookmarked_by = array();
    			$bookmarked_by = array_unique($bookmarked_by);
    			foreach ($bookmarked_by as $user) {
    				$avt_list .=  get_avatar($user , 30);
    			}
    			return $content.'<style>.bookmarked-avatar img{margin: 3px;}</style><div class="bookmarked-avatar"><h5>Bookmarked By Members</h5>'.$avt_list;
    		}
    	
    		return $content;
    	}
    

    Any other suggestion would be sincerely appreciated.

    Just trying to make avatar that is displayed clickable to the user profile page.

    Thank you.

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #27344

    Hi,
    You will need to change this line

    
    $avt_list .=  get_avatar($user , 30);
    
    

    to

    
    
    $avt_list .= '<a href="' . bp_core_get_user_domain( $user ) . '">' . get_avatar( $user, 30 ) . '</a>';
    
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 171
    JohnnyNW on #27345

    WOW – that was awesome! Thank you so much!

    You’re like the magic man! LOL

    Just awesome 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #27346

    🙂

The topic ‘ [Resolved] Get avatar with link to profile’ is closed to new replies.

This topic is: resolved