Search
Close this search box.

How to display logged in users avatar in BuddyPress

To display the avatar of a logged-in user in BuddyPress, you can use the bp_loggedin_user_avatar function. This function will display the avatar of the currently logged-in user.

Here’s an example of how you can use this function:

<?php 

// Display logged in users avatar in BuddyPress
// More snippets at wpunplugged.com 

if ( is_user_logged_in() ) : ?>
	<div class="logged-in-user-avatar">
		<?php bp_loggedin_user_avatar( 'type=thumb&width=50&height=50' ); ?>
	</div>
<?php endif; ?>

This code will display the avatar of the logged-in user in a div element, with the avatar image being 50 pixels wide and 50 pixels tall. The type parameter specifies the type of avatar to display, and the width and height parameters specify the dimensions of the avatar image.

You can also use the bp_displayed_user_avatar function to display the avatar of a specific user, rather than the logged-in user. To use this function, you will need to pass the user’s ID as a parameter. For example:

<?php 

// Display logged in users avatar in BuddyPress
// More snippets at wpunplugged.com 

bp_displayed_user_avatar( 'type=thumb&width=50&height=50&user_id=123' ); ?>

This will display the avatar of the user with an ID of 123, using the same parameters as the bp_loggedin_user_avatar function.

Share this post

You might also like...

Comment

Your email address will not be published. Required fields are marked *