Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding New Profile Tab Content

  • @saturdaysound

    Participant

    Hello!

    I’m having trouble with getting my content to work when adding a new tab to the profile page. Here’s my code:

    
    function profile_tab_favourites() {
      global $bp;
      bp_core_new_nav_item( array( 
        'name' => __( 'Favourites' ), 
        'slug' => 'favorites', 
        'screen_function' => 'favourites_screen', 
        'position' => 40 ) 
      );
    
      function favourites_screen() {
        //add title and content here – last is to call the members plugin.php template
        add_action( 'bp_template_title', 'favourites_title' );
        add_action( 'bp_template_content', 'favourites_content' );
        bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'buddypress/members/single/plugins' ) );
      }
    
      function favourites_title() {
        echo 'Title';
      }
    
      function favourites_content() {
        echo 'Content';
      }
    }
    add_action( 'bp_setup_nav', 'profile_tab_favourites' );

    Adding the tab works great, but my screen function doesn’t work at all. infact, when I click on my tab I just get 404’d and there’s no content echoing at all.

    I have searched and searched for an answer everywhere and I can’t find anyway to figure this out. I would love some advice.

    If you need me to supply anything, just let me know!

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • @shanebp

    Moderator

    Try changing this:

    bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘buddypress/members/single/plugins’ ) );
    

    To this:

    bp_core_load_template( 'members/single/plugins' );

    @danbp

    Participant

    @saturdaysound

    Participant

    @shanebp

    Thanks for that! It’s doing something different now, but not what I need unfortunately.

    What is happening now is that the Title and Content are the only thing on the page, there is no other content… not my page header, not the Buddypress profile page, nothing at all.

    Here’s the new code.

    function profile_tab_favourites() {
          global $bp;
     
          bp_core_new_nav_item( array( 
                'name' => 'Favourites', 
                'slug' => 'favourites', 
                'screen_function' => 'favourites_screen', 
                'position' => 40,
          ) );
    }
    add_action( 'bp_setup_nav', 'profile_tab_favourites' );
     
     
    function favourites_screen() {
        //add title and content here - last is to call the members plugin.php template
        add_action( 'bp_template_title', 'favourites_title' );
        add_action( 'bp_template_content', 'favourites_content' );
        bp_core_load_template( 'buddypress/members/single/plugins' );
    }
    function favourites_title() {
        echo 'Title';
    }
    
    function favourites_content() { 
        echo 'Content';
    }

    -NOTE: my buddypress templates are all inside a directory called “buddypress” on root, hence the “buddypress/members/single/plugins” not “members/single/plugins”.

    Any known reason for this behaviour?

    @shanebp

    Moderator

    Did you try it with just “members/single/plugins” ?

    @saturdaysound

    Participant

    @shanebp

    Thanks again for the advice, when I switch to “members/single/plugins” it just lists all the members. There’s none of the content I set, or the profile page.

    It’s just a long list of the members registered with the site.

    @shanebp

    Moderator

    Add this to bp_core_new_nav_item

    'parent_url'      => bp_loggedin_user_domain() . '/favourites/',
    'parent_slug'     => $bp->profile->slug,
    'default_subnav_slug' => 'favourites'

    or this:

    'parent_url'      => bp_displayed_user_domain()  . '/favourites/',
    'parent_slug'     => $bp->profile->slug,
    'default_subnav_slug' => 'favourites'

    @saturdaysound

    Participant

    That did it!

    You’re the man @shanebp , You are the man!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding New Profile Tab Content’ is closed to new replies.
Skip to toolbar