Skip to:
Content
Pages
Categories
Search
Top
Bottom

Create Sub Nav Menu Item in Profile

  • @userabuser

    Participant

    Hi,

    I’m having trouble creating a Sub Menu Item under a Parent Menu Item.

    The parent menu item as shown below, named “TEST”, shows correctly, but the tabs named “SUB NAV” and “SUB NAV 2” don’t show at all.

    `
    function my_setup_nav() {
    global $bp;

    bp_core_new_nav_item( array(
    ‘name’ => ‘TEST’,
    ‘slug’ => $bp->account->slug,
    ‘position’ => 10,
    )
    );

    $em_link = $bp->loggedin_user->domain . $bp->account->slug . ‘/’;

    bp_core_new_subnav_item( array(
    ‘name’ => ‘SUB NAV’,
    ‘slug’ => ‘account-sub’,
    ‘parent_url’ => $em_link ,
    ‘parent_slug’ => $bp->account->slug,
    ‘position’ => 10,
    ‘item_css_id’ => ‘xx’
    )
    );
    bp_core_new_subnav_item( array(
    ‘name’ => ‘SUB NAV 2’,
    ‘slug’ => ‘account-sub-2’,
    ‘parent_url’ => $em_link ,
    ‘parent_slug’ => $bp->account->slug,
    ‘position’ => 20,
    ‘item_css_id’ => ‘xx-2’
    )
    );
    }

    add_action( ‘bp_setup_nav’, ‘my_setup_nav’, 99 );
    `

    Any suggestions?

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

    Moderator

    Each subnav item requires a screen function or it will not be created.
    example: ‘screen_function’ => ‘some_function’,

    You can create an empty function for testing:
    function some_function() { }

    You probably need to add a screen function to the parent nav item too.

    @userabuser

    Participant

    Thanks for your reply Shane.

    I tried adding the screen function with an empty test function to no avail. If I change the slug to $bp->profile->slug then the Sub Nav item appears as a sub item of the Profile Parent tab but seems not to work with my custom added “TEST” parent.

    It seems like its a slug issue, but whether I am declaring,

    ‘slug’ => $bp->account->slug
    or
    ‘slug’ => ‘account’

    …it still doesn’t seem to take. When I dump the $bp global varaible, I can see my parent menu item exists as it should, so that doesn’t seem to be the issue. Thanks for your input thus far.

    @modemlooper

    Moderator

    is account an actual BP component?

    @userabuser

    Participant

    @modemlooper,

    Its not a BP component, its actually a page under the page post_type.

    I’ve now got my code working, it was conflicting with the BP custom profile menu plugin (or vice versa). After disabling that plugin and applying the suggestion as provided by Shane, it now works.

    However when using the BP custom profile menu plugin, whatever pages were added (as per the normal WordPress Menu system) would correctly load themselves upon navigating to said URL.

    With the manual method I am using above, the URLs do 404 on me.

    So using the screen_function callback I can run a query for the page named account – which is fine, happy to do that.

    But I’d like to know whether there is a particular method I need to apply (rewrite rule) to have the links work (navigate to their permalink destination) without having to use the screen function?

    Anyway, for now thanks for the assistance and to Shane for providing the insight I needed to get this working correctly.

    @funmi-omoba

    Participant

    @userabuser,

    Please anyway to help me out on how to create subnav.

    below is my topic.
    https://buddypress.org/support/topic/how-to-add-a-link-to-a-link-to-friends-subnav/

    regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Create Sub Nav Menu Item in Profile’ is closed to new replies.
Skip to toolbar