Blog: WordPress
Tech team working

Add Edit Profile Link In bbPress

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

bbPress is a popular WordPress plugin for creating forums.

Sometimes, it is used by itself, but often, it is used in conjunction with BuddyPress, another WordPress plugin for creating self-hosted social networks.

As it turns out, many folks have sought out how to add a link to edit your profile on bbPress, outside of the normal flow of the plugin.

Why might you do this?

One good reason would be presenting a front-facing means of changing your profile information. The back-end of WordPress isn’t always desirable to have our customers look at, but we still want them to have the ability to display and edit their profile.

Here’s a solution that works in most cases to output a profile edit link for bbPress-powered sites.

The Code Snippet

You’ll probably want to add this function to your theme by using a hook, or running this function at a specific place.
If you want to use this straight-up in a theme file, be sure to unwrap this from the function brackets.


<?php
function ld_bbpress_edit_link() {
	global $wp;
	
	$current_url = home_url($wp->request);
	if (is_user_logged_in()) {
		global $current_user;
		get_currentuserinfo();
		
    $user_ID = get_current_user_id();
		echo get_avatar($user_ID, 48);?>
			<a href="<?php echo bbp_user_profile_url( bbp_get_current_user_id() ); ?>edit" >Edit Profile</a>
	} else {
            // Do something else here.
        }
}
?>

What’s Going On Here?

First, we’re setting up a global query. Then we’re getting the current URL.

Next, we see if our user is logged in or not. If they aren’t logged in, we go to the else statement.

If they are logged in, we get the current user and their information. We store the current user’s ID in a variable.

Then we echo (read: output) the avatar of that logged in user to the screen, in a 48 by 48 pixel image.

Then we output a link to edit their bbPress profile. (The URL will end in /edit.)

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

Join the Conversation

Your email address will be kept private. Required fields marked *.