How to add @mention username under bbPress user avatars in WordPress

To add a @mention username under bbPress user avatars using the functions.php file, you can use the bbp_theme_after_user_avatar action hook. This hook allows you to add content after the user avatar on bbPress pages.

Here is an example of how you can use this hook to add a @mention username under bbPress user avatars:

// Add @mention username under bbPress user avatars in WordPress
// More snippets at wpunplugged.com 

function add_mention_username_under_avatar() {
    $user_id = bbp_get_user_id();
    $user_login = bbp_get_user_login( $user_id );
    echo '<div class="mention-username">@' . esc_html( $user_login ) . '</div>';
}
add_action( 'bbp_theme_after_user_avatar', 'add_mention_username_under_avatar' );

In this example, we are using the bbp_get_user_id() and bbp_get_user_login() functions to get the user ID and login name of the user whose avatar is being displayed. We then use the esc_html() function to escape the login name and add it to the page as a @mention username.

It’s important to note that this code will add the @mention username under the user avatar on all bbPress pages. If you only want to add the @mention username in certain contexts, you will need to add additional checks before displaying the username.

Share this post

You might also like...

Comment

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