I am trying to create a dynamic buddypress tab linked to a dynamic url that looks like this localhost/wordpress/slug/username

this tab should appear to any user visiting another user's profile,, and when clicked it should redirect to the user visited and not the user visiting , I mean that the username at the end of my URL should be replaced by the username of the current profile visited

I am using the wp_redirect function to redirect the user to this url but the probleme is that i don't know how to write this url ?

I've tried to create a variable like so $user = wp_get_current_user(); to includ it like so wp_redirect( "http://localhost/wordpress/slug/$user->display_name" ); but the final result is http://localhost/wordpress2/slug/ i'm not even sure i should call this function current user so please someone help me

keep in mind that i'm writing my code in the function.php file in my theme folder

thats the code i added

$user = wp_get_current_user();

add_action( 'bp_setup_nav', 'create_tab3', 303 );
function create_tab3() {
    global $bp;
            'name'                    => 'my name',
            'slug'                    => 'slug', 
            'position'                => 21, 
            'default_subnav_slug'     => 'mySlug', // We add this submenu item below 
            'screen_function'         => 'redirect_user_to_tab3',

function redirect_user_to_tab3(){
    global $bp;
    wp_redirect( "http://localhost/wordpress2/slug/$user->display_name" );



You can't use an object variable, $user->display_name, in a string.

And why would you want a tab that links back to the member being viewed? You're already viewing that member.

This will provide the url of the displayed member: bp_displayed_user_domain()

So you could do this:

function redirect_user_to_tab3(){
    bp_core_redirect( bp_displayed_user_domain() );

If you just want the user name for the currently displayed user so that you can build an url, you could do this:

function redirect_user_to_tab3(){
    $url = site_url() . '/slug/' . bp_get_displayed_user_username();
    bp_core_redirect( $url );
| improve this answer | |
  • thanks for reply but you didn't understand me ,,, i fixed the first part of my probleme by declaring my var $user = wp_get_current_user(); inside the function function redirect_user_to_tab3() and this worked fine for my profile ,,,, the tab i create doesn't link to the member viewed wich has the slug of members ,,, my tab has a different slug then the username of the profile being viewed (user2) so i want the final url like this http://localhost/wordpress2/slug/user2 ,,, i know i should call something different than ` wp_get_current_user()` to find infos about the profile viewed ,, – dantosso Nov 10 '15 at 18:30
  • See my edited answer above. – shanebp Nov 10 '15 at 18:47
  • thats it ,,, it worked just like i want ,,,,,, you're a master ,,,, it's been 2 weeks i'm trying to find the solution ,,,, i cant thank you enough ,,,, – dantosso Nov 10 '15 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.