Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress new tab to redirect to normal slug!


  • gurusurfer
    Participant

    @gurusurfer

    Hi,

    I have this function hoping to get the new created tab in buddypress to redirect to the normal wordpress contact page I have.

    add_action('bp_setup_nav', 'mb_bp_profile_menu_posts', 301 );
    function mb_bp_profile_menu_posts() {
    global $bp;
    bp_core_new_nav_item(
    	array(
            'name' => 'Contact us',
            'slug' => 'contact-us', 
            'position' => 11, 
    	)
    );
    }
    

    But this is forcing the buddypress member profile in the slug before the contact-us which will lead to a 404 page. Here is an example of what the upon functions is yielding and what i am trying to achieve:

    Current tab link redirects to:

    http:/exampleurl/members/user-name/contact-us

    and what I am trying to achieve is:

    http:/exampleurl/contact-us

    Would love some help and thanks.

Viewing 5 replies - 1 through 5 (of 5 total)

  • shanebp
    Moderator

    @shanebp

    Please use the code button when sharing code.

    bp_core_new_nav_item will always add links that are relative to a member profile.

    You can add a link and then use a redirect in the screen function.

    Try:

    function add_contact_tab() {
    	global $bp;
    	
    	bp_core_new_nav_item( array(
    		'name'                  => 'Contact Us',
    		'slug'                  => 'contact-us',
    		'parent_url'            => $bp->displayed_user->domain,
    		'parent_slug'           => $bp->profile->slug,
    		'screen_function'       => 'contact_screen',			
    		'position'              => 11,
    		'default_subnav_slug'   => 'contact-us'
    	) );
    
    }
    add_action( 'bp_setup_nav', 'add_contact_tab', 100 );
    
    function contact_screen() {
    	bp_core_redirect( site_url( '/contact-us/' ) );
    }

    gurusurfer
    Participant

    @gurusurfer

    Sorry about the Code button and thanks for the response!

    Unfortunately the redirection did not trigger with the above snippet. Any idea why?


    shanebp
    Moderator

    @shanebp

    It works fine on my test BP installation.


    Bael Harman
    Participant

    @bael-harman

    Is there a way to add tabs for specific roles only?


    Bael Harman
    Participant

    @bael-harman

    I would like to add both a Photos and a Videos menu tab for subscriber roles only.

    In photos, Subscribers can upload pictures display them in a grid.

    In videos, Subscribers can upload videos and display them in a playlist.

    I have not found a plugin to do this.

    Thank you all and God bless.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Buddypress new tab to redirect to normal slug!’ is closed to new replies.
Skip to toolbar